关于backbone.js

对于collection调用fetch()方法,则以get方式,去服务器请求资源

 1 BookShelf = Backbone.Collection.extend({
 2                   model:Book
 3               });
 4 
 5 var bookShelf = new BookShelf;
 6 
 7 bookShelf.fetch({url:'collection.do',success:function(collection,response) {
 8                   collection.each(function(book) {
 9                       alert(book.get('title'));
10                   });
11               }});

 

collection在fetch得到数据之后,会调用reset方法,所以,需要在collection中定义reset方法,或者绑定reset方法

 

1 bookShelf.bind('reset',function(){
2                   bookShelf.each(function(book) {
3                       //将collection渲染到页面
4                   });
5               });

 

Router

Backbone.Router将链接中的内容作为url路径

 

 1 var AppRouter = Backbone.Router.extend({
 2                   routes: {
 3                       "*action":"defaultRoute"
 4                   },
 5                   defaultRoute:function(actions) {
 6                       alert(actions);
 7                   }
 8               });
 9               
10               var app_router = new AppRouter;
11               Backbone.history.start();
1 <a href="#action">testAction</a>

 

posted @ 2013-05-15 16:18  system("cls")  阅读(139)  评论(0)    收藏  举报