0

我有很多使用模板的视图。视图渲染完美地工作,现在进入我的路由器,我正在寻找一种在所有视图渲染时触发事件的方法!我使用了像 LAB.js 这样的 js 加载器,但没有任何效果!

在所有渲染之后,我将事件输入到萤火虫控制台中,它的工作!

我可以如何以及在此处放置我的事件,以便在所有视图呈现时触发它!

**我的活动:**

$('div[id ^="solfg_"]').mobilyblocks();

**路由器:**

(function () {

 window.AppRouter = Backbone.Router.extend({
 routes: {
  ""  : "init"
 },

 init: function(){

   this.solfsmodel = new Solfs();
   this.solfsmodel.fetch(); 
   this.solfsView = new SolfsView({model: this.solfsmodel});

 }

});
var app_router = new AppRouter;
Backbone.history.start();
}(jQuery));

谢谢

更新: 同样的问题

4

2 回答 2

1

我发现解决方案只是使用 jquery 中的 $.when().then(),我从未见过这个 jquery 函数真是太神奇了。

*我的解决方案:*

(function () {

 window.AppRouter = Backbone.Router.extend({
 routes: {
   ""  : "run"
 },

initialize: function(){
  this.solfsmodel = new Solfs();

  this.solfsView = new SolfsView({model: this.solfsmodel});

},
run: function(){
  $.when(
     this.solfsmodel.fetch(); 
  ).then(function(){
     *$('div[id ^="solfg_"]').mobilyblocks();*
  });
}
});
var app_router = new AppRouter;
Backbone.history.start();
}(jQuery));
于 2012-01-20T01:18:55.580 回答
0

如果您只需要等待集合被获取,您可以使用方法的success回调(来源: http ://backbonejs.org/#Collection-fetch )。fetch

在使用其他库之前最好使用 Backbone.js 方法。

所以你的代码应该是这样的:

(function () {

    window.AppRouter = Backbone.Router.extend({
        routes: {
            ""  : "run"
        },

        initialize: function(){
            this.solfsmodel = new Solfs();
            this.solfsView = new SolfsView({model: this.solfsmodel});
        },

        run: function(){
            this.solfsmodel.fetch({
                success: function () { 
                    $('div[id ^="solfg_"]').mobilyblocks();
                }
            );
        }
    });
    var app_router = new AppRouter;
    Backbone.history.start();
}(jQuery));
于 2012-01-20T07:56:37.617 回答