Sproutcore 嵌套数组一对多绑定
我有三层对象,每一层都是一对多。我希望,当选择不同的笔记本时,页面和列视图元素能够获得级联更新。
笔记本>页数>列
使用notebooksController和notebookController我可以绑定
App.Notebook = SC.Record.extend({
name: SC.Record.attr(String),
pages: SC.Record.toMany('App.Page', {isMaster: YES, inverse: 'notebook'})
});
App.Page = SC.Record.extend({
pageNumber: SC.Record.attr(Number),
notebook: SC.Record.toOne('App.Notebook', {isMaster: NO, inverse: 'pages'}),
columns: SC.Record.toMany('App.Column', {isMaster: YES, inverse: 'page'})
});
App.Column = SC.Record.extend({
columnNumber: SC.Record.attr(Number),
page: SC.record.toOne('App.Page', {isMaster: NO, inverse: 'columns'})
});
接下来,我似乎无法让pagesController的内容绑定工作。我希望pageController、pageController、columnsController 和columnController 的内容向下级联,以便当用户单击不同的笔记本时,呈现的视图会自动切换到正确的内容。
ArrayController notebooksController
// contents filled from fixture
ObjectController notebookController
// bound to notebooksController selection
ArrayController pagesController
// contentBinding: 'notebookController.pages' does not work!
ObjectController pageController
// bound to pagesController selection
// and down to column
I have three tiers of objects, each as one to many. I'd like, when a different notebook is selected, that the page and column view elements get cascading updates.
Notebook > Pages > Columns
With notebooksController and notebookController I can bind
App.Notebook = SC.Record.extend({
name: SC.Record.attr(String),
pages: SC.Record.toMany('App.Page', {isMaster: YES, inverse: 'notebook'})
});
App.Page = SC.Record.extend({
pageNumber: SC.Record.attr(Number),
notebook: SC.Record.toOne('App.Notebook', {isMaster: NO, inverse: 'pages'}),
columns: SC.Record.toMany('App.Column', {isMaster: YES, inverse: 'page'})
});
App.Column = SC.Record.extend({
columnNumber: SC.Record.attr(Number),
page: SC.record.toOne('App.Page', {isMaster: NO, inverse: 'columns'})
});
Following this, I can't seem to get the content binding for pagesController to work. I want the contents of pagesController, pageController, columnsController, and columnController to be cascaded down so that when a user clicks a different notebook, the views presented automatically flick across to the correct content.
ArrayController notebooksController
// contents filled from fixture
ObjectController notebookController
// bound to notebooksController selection
ArrayController pagesController
// contentBinding: 'notebookController.pages' does not work!
ObjectController pageController
// bound to pagesController selection
// and down to column
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有一个笔记本,请尝试
Assuming you have a single Notebook, try
我找到了答案。
事实证明,您确实可以简单地使用 App.notebookController.pages。
问题是,我的灯具设置不正确。将子级映射到父级是不够的,必须将父级映射回子级。
我最初有:
当我执行以下操作时,一切都已修复:
I found the answer.
Turns out you can indeed simply use App.notebookController.pages.
The problem was, my fixtures were not set up correctly. It is not enough to map the child to the parent, the parent has to be mapped back to the child.
I originally had:
And was all fixed when I did the following: