骨干和Rails嵌套路线 [英] Backbone and Rails Nested Routes
本文介绍了骨干和Rails嵌套路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在轨道定义了以下路线:
I have the following routes defined in rails:
resources :accounts do
resources :transactions
end
这导致类似的网址:
/accounts/123/transactions/1
有一个简单的方法来此映射建立骨干模式?
Is there an easy way to map this to a backbone model set up?
推荐答案
原来骨干很容易通过在模型嵌套集合支持此如下:
Turns out backbone quite easily supports this by nesting a collection in a model as follows:
var Account = Backbone.Model.extend({
initialize: function() {
this.transactions = new TransactionsCollection;
this.transactions.url = '/account/' + this.id + '/transactions';
this.transactions.bind("reset", this.updateCounts);
},
});
这实现正是我想要的。
您可以阅读更多关于它在这里:<一href=\"http://documentcloud.github.com/backbone/#FAQ-nested\">http://documentcloud.github.com/backbone/#FAQ-nested
You can read more about it here: http://documentcloud.github.com/backbone/#FAQ-nested
这篇关于骨干和Rails嵌套路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文