创建应用和模型和控制器

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 函数。 它可以用来将现有数据填充到控制器

posted @ 2014-11-12 23:27  向着太阳生  阅读(172)  评论(1编辑  收藏  举报