在 Backbone.js 中的显示视图中嵌套创建视图
好吧,所以我对骨干完全陌生,在任何地方都找不到我的问题的答案。 我使用backbone-rails,所以我使用jst 模板系统。我有两个模型,其中一个模型,说ModelA可以有多个ModelB,但ModelB只能有一个ModelA(HasMany关系)。
我想要实现的是,我有网页的左侧和右侧部分,其中左侧页面始终列出 ModelA,即索引视图,右侧部分从左侧显示当前选择的 ModelA,显示视图。右侧部分还列出了 ModelB,并显示用于创建属于所选 ModelA 的 ModelB 的表单。
--------------------------------------
|___ModelA list__| ModelA - 2 details |
|_______1________| |
|///////2////////| ModelB Form |
|_______3________| |
|_______4________|_____ModelB List_____|
|_______5________|__________1__________|
|_______6________|__________2__________|
|_______7________|__________3__________|
|_______8________|__________4__________|
ModelB 列表仅显示属于 ID 为 2 的 ModelA 的 ModelB 对象
因此,我向 ModelA 添加了类似的内容
initialize: function() {
this.modelbs = new Appname.Collections.ModelBCollection(this.get("modelbs"));
this.modelbs.url = this.url() + "/modelbs";
}
,并通过添加解决了左侧空间中 ModelA 的列表问题
this.index()
所有路由器操作(例如 show)中的
因此,一亿美元的大问题是,A)如何从 ModelA 中的 show 操作调用路由器操作(例如 ModelB 中的视图)? B) 如何在 ModelA 详细信息部分中呈现 ModelB 的表单(显示操作)并将关系添加到 ModelA 并让 ModelB 视图负责保存。
谢谢!
Okey, so I am totally new to backbone, and can't find the answer to my question anywhere.
I use backbone-rails so I'm using the jst templating system. I have two models, where one of the models, say ModelA can have multiple ModelB, but ModelB can only have one ModelA (HasMany relationship).
What I want to achieve is that I have a left and a right part of the webpage, where the left page always is listing ModelA, the index view so to say, and the right part show the current selected ModelA from the left side, the show view. The right part also lists ModelB and displays a form for creating ModelB's beloning to the selected ModelA.
--------------------------------------
|___ModelA list__| ModelA - 2 details |
|_______1________| |
|///////2////////| ModelB Form |
|_______3________| |
|_______4________|_____ModelB List_____|
|_______5________|__________1__________|
|_______6________|__________2__________|
|_______7________|__________3__________|
|_______8________|__________4__________|
ModelB List shows only ModelB objects that belong to ModelA with id 2
So, I have added something like this to ModelA
initialize: function() {
this.modelbs = new Appname.Collections.ModelBCollection(this.get("modelbs"));
this.modelbs.url = this.url() + "/modelbs";
}
and solved the listing of ModelA in the left space by adding
this.index()
in all the router actions (e.g. show)
So the big hundred million dollar question is, A) How to call a router action, say view in ModelB, from the show action in ModelA? and B) How to render the form for ModelB in the ModelA details section (show action) and adding the relationship to ModelA and let the ModelB view take care of the saving.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是子视图。
您可能对此感兴趣:http://ricostacruz.com/backbone-patterns/#sub_views
What you are looking for is subview.
You might be interested in this: http://ricostacruz.com/backbone-patterns/#sub_views