例如,在某一事件发生后,我会:
render: function () {
new FavoritesView({el: $A.el('#mm'));
new FeedView({el: $A.el('#at_view'));
new AccountView();
}它创建3个视图和3个ajax请求。以前,我使用的是一个框架,它只使用一个框架,因为它合并了请求。
有没有办法在脊梁上做到这一点?
发布于 2014-07-25 23:33:50
您没有提供太多的细节或代码,但是如果有一个请求来检索多个对象(按照您以前的框架),那么该请求很可能不是REST接口。默认情况下,主干希望对其模型(因此是集合)使用REST接口(Ruby风格),因此无法“开箱即用”。
然而,主干很容易扩展,您当然可以重写模型/集合的fetch方法来使用非REST。更好的方法可能是为三个模型/集合提出自己的AJAX请求,然后在创建模型/集合时将适当的数据输入模型/集合,从而完全避免骨干fetch。类似于:
render: function() {
$.getJSON("url/to/aggregated/data", function(data) {
var favorites = new Favorites(data.favorites);
var feed = new Feed(data.feed);
var account = new Account(data.account);
new FavoritesView({el: $A.el('#nm'), collection: favorites);
new FeedView({el: $A.el('#at_view'), model: feed);
new AccountView({model: account});
});
}https://stackoverflow.com/questions/24963160
复制相似问题