首页 > 其他 > 详细

(四)backbone - DEMO - 通信录

时间:2014-12-16 19:03:09      阅读:299      评论:0      收藏:0      [点我收藏+]

DEMO介绍

是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 });

 

(四)backbone - DEMO - 通信录

原文:http://www.cnblogs.com/huair_12/p/4167733.html

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