首页 > 其他 > 详细

创建应用和模型和控制器

时间:2014-11-13 00:18:15      阅读:335      评论:0      收藏:0      [点我收藏+]

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

创建应用和模型和控制器

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!