标签:style blog http ar io color sp for strong
是DEMO - User List 的扩展,增加查询
大体实现
•创建Contact Model
1 var Contact = Backbone.Model.extend({ 2 defaults: { 3 name: ‘小强‘, 4 email: ‘walker@dead.com‘ 5 }, 6 // validate user name 7 validate: function(attrs,options) { 8 if (attrs.name == "") { 9 return "what‘s the name?"; 10 }; 11 }, 12 // for user search 13 filter: function(query) { 14 if (typeof(query) === ‘undefined‘ || query === null || query === ‘‘) return true; 15 query = query.toLowerCase(); 16 return this.get(‘name‘).toLowerCase().indexOf(query) != -1 || this.get(‘email‘).toLowerCase().indexOf(query) != -1; 17 } 18 });
•创建Contact Collection
1 var Contacts = Backbone.Collection.extend({ 2 model: Contact, 3 localStorage: new Store(‘my-contacts‘) // 存至本地 4 });
标签:style blog http ar io color sp for strong
原文地址:http://www.cnblogs.com/huair_12/p/4167733.html