0

テンプレートを操作するビューがたくさんあります。ビューを使用したレンダリングは完全に機能します。ルーターに、すべてのビューがレンダリングされたときにイベントをトリガーする方法を探しています。LAB.jsのようなjsローダーを使用しましたが、何も機能しません!

すべてレンダリングされた後、私はイベントをfirebugコンソールに入力し、それは機能します!

すべてのビューがレンダリングされたときにトリガーされるように、イベントを配置する方法と方法を教えてください。

**私のイベント:**

$('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 に答える