gpt4 book ai didi

Sproutcore 嵌套数组一对多绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 13:38:37 26 4
gpt4 key购买 nike

我有三层对象,每一层都是一对多的。我想选择其他笔记本时,页面和列 View 元素会获得级联更新。

笔记本 > 页面 > 列

使用 notebooksController 和 notebookController 我可以绑定(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'})
});

在此之后,我似乎无法让 pagesController 的内容绑定(bind)工作。我希望 pagesController、pageController、columnsController 和 columnController 的内容被级联下来,这样当用户单击不同的笔记本时,呈现的 View 会自动切换到正确的内容。
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

最佳答案

假设您有一个笔记本,请尝试

App.notebookController = SC.ObjectController.create({
// call App.notebookController.set('content', aNotebook)
// to set the content on this controller
});

App.pageController = SC.ArrayController.create({
// the notebookController is a proxy to the its content, so you dont need
// 'content' in the binding contentBinding: 'App.notebookController.pages'

// bind the list view to App.pagesController.arrangedObjects. If you look in the code
// arranged objects is a reference to the array controller itself, which has array methods
// on it
});

App.pageSelectionController = SC.ObjectController.create({
// You need to add
//
// selectionBinding: 'App.pageSelectionController.content
//
// to the collection view where you select the page

// you can do this in places to see when things change. This controller is just a proxy
// to the selected page.
selectionDidChange: function(){
console.log('page selection changed to [%@]'.fmt(this.get('content');
}.observes('content')
});

App.columnsController = SC.ArrayController.create({
contentBinding: 'App.pageSelectionController.columns'

// again, where you want to show the columns, bind to
// App.columnsController.arrangedObjects
});

关于Sproutcore 嵌套数组一对多绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6543320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com