码迷,mamicode.com
首页 > 其他好文 > 详细

创建应用和模型和控制器

时间:2014-11-13 00:21:29      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   数据   on   art   cti   bs   ad   

1、创建应用

Myapp = Ember.Application.create({

  name:‘kevin‘,

  age:18,

  ready:function(){

    alert(‘加载应用时自动调用该初始化方法,属性通过Myapp.name访问,这里的对象可有可无‘)

  }

});

2、创建模型models

Myapp.Song = Ember.Object.extend({

  title: null, artist: null, genre: null, listens: 0

})

实例化模型对象

var mySongs = Song.create({title: ‘Son of the Morning‘, artist: ‘Oh, Sleeper‘, genre: ‘Screamo‘})

3、创建控制器

Myapp.songsController = Ember.ArrayController.create({

content: [],

init: function(){

var song = Myapp.Song.create({ title: ‘Son of the Morning‘, artist: ‘Oh, Sleeper‘, genre: ‘Screamo‘ });

this.pushObject(song);

}

});

注:init 函数不是必需的,但它很方便,因为 songsController 一旦就绪,就会触发 init 函数。 它可以用来将现有数据填充到控制器

创建应用和模型和控制器

标签:io   ar   sp   数据   on   art   cti   bs   ad   

原文地址:http://www.cnblogs.com/toward-the-sun/p/4093832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!