如何在使用 Backbone.js 渲染视图后触发事件?
我有很多使用模板的视图。视图的渲染工作完美,现在在我的路由器中,我正在寻找一种在渲染所有视图时触发事件的方法! 我使用了像 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));
谢谢
更新: 同样的问题
I have many Views whos work with templates. The Rendering with the Views work perfectly, now into my Router i'm seeking to a way to trigger an Event when all Views rendered!
I used js loader like LAB.js but nothing work!
After all rendered i enter the event into the firebug console and it's work!
How and Here can i place my event so that it's trigger when all views rendered!
**My Event : **
$('div[id ^="solfg_"]').mobilyblocks();
**Router : **
(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));
Thank you
update : same problems
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现解决方案只是使用 jquery 中的 $.when().then() ,真的很神奇,我从未见过这个 jquery 函数。
*我的解决方案:*
I found the solution just use $.when().then() from jquery, really amazing that i never saw this jquery function.
*My Solution : *
如果您只需要等待获取集合,您可以使用
fetch
方法的success
回调(来源:http://backbonejs.org/#Collection-fetch)。在使用其他库之前最好使用 Backbone.js 方法。
所以你的代码应该是这样的:
You can use the
success
callback offetch
method if you just need to wait that the collection is fetched (source: http://backbonejs.org/#Collection-fetch).It's preferable to use Backbone.js method before use other librairies.
So your code should look like: