计划,每天学习两小时,坚持带来大改变。

Marionette:Marionette App:Todo_model(五)

前端开发 阿尤 3264浏览 0评论


最后,我们要定义表示Todo item的model和collection。

Todos.js:

TodoMVC.module('Todos', function(Todos, App, Backbone, Marionette, $, _){ // Todo Model // ---------- Todos.Todo = Backbone.Model.extend({ localStorage: new Backbone.LocalStorage('todos-backbone'), defaults: { title : '', completed : false, created : 0 }, initialize : function() { if (this.isNew()) this.set('created', Date.now()); }, toggle : function() { return this.set('completed', !this.isCompleted()); }, isCompleted: function() { return this.get('completed'); } }); // Todo Collection // --------------- Todos.TodoList = Backbone.Collection.extend({ model: Todos.Todo, localStorage: new Backbone.LocalStorage('todos-backbone'), getCompleted: function() { return this.filter(this._isCompleted); }, getActive: function() { return this.reject(this._isCompleted); }, comparator: function( todo ) { return todo.get('created'); }, _isCompleted: function(todo){ return todo.isCompleted(); } }); });
 
转自:http://www.ituring.com.cn/article/31888


转载请注明:阿尤博客 » Marionette:Marionette App:Todo_model(五)

游客
发表我的评论 换个身份
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  • 验证码 (必填)点击刷新验证码