如何从主 dojo 商店创建较小的 dojo 商店并保持两者同步?
我有一个像这样的主存储:
var data = {
identifier: "pkid",
items: [ {pkid: 3456, name: "Tom", kids: [ {pkid: 3459, kidname: "Jenny"}, {pkid: 45698, kidname: "Jimmy"} ]
}
var mainStore = new ItemFileWriteStore({data: data});
var mainGrid = new var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'},
document.createElement('div'));
/*append the new grid to the div*/
dojo.byId("maingridDiv").appendChild(grid.domNode);
/*Call startup() to render the grid*/
grid.startup();
var selectedRow = mainGrid.getItem(0);
var kids = mainStore.getValues(selectedRow, "kids");
var kidsData =
{
identifier: "pkid",
items: kids
}
var kidsStore = new ItemFileWriteStore({data: kidsData});
var kidsGrid = ........
store: kidsStore,
..............
首先,kidsData 中的引用 kids 不起作用,因为渲染 kidsGrid 时 dojo 会抛出错误。
其次,假设我想删除 kidsStore 中的一个项目(行或孩子),我希望该孩子也从 mainStore 中删除。有没有一个好的、有效的解决方案?
I have a master store like:
var data = {
identifier: "pkid",
items: [ {pkid: 3456, name: "Tom", kids: [ {pkid: 3459, kidname: "Jenny"}, {pkid: 45698, kidname: "Jimmy"} ]
}
var mainStore = new ItemFileWriteStore({data: data});
var mainGrid = new var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'},
document.createElement('div'));
/*append the new grid to the div*/
dojo.byId("maingridDiv").appendChild(grid.domNode);
/*Call startup() to render the grid*/
grid.startup();
var selectedRow = mainGrid.getItem(0);
var kids = mainStore.getValues(selectedRow, "kids");
var kidsData =
{
identifier: "pkid",
items: kids
}
var kidsStore = new ItemFileWriteStore({data: kidsData});
var kidsGrid = ........
store: kidsStore,
..............
First of all the reference kids in kidsData does not work as dojo throws error when rendering kidsGrid.
Secondly suppose I want to delete an item (row or kid) in kidsStore, I want that kid to be deleted from mainStore as well. Is there a good solution that works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,ItemFileWriteStore 和 JsonRestStore 不能使用相同的结构。
IFWS 仅使用数组,而 JRS 混合使用数组/对象。
恐怕你得亲自处理这些关系。例如,当编辑孩子后单击“验证”时,您将循环它们,然后更新 JRS,然后 JRS.save()
First, ItemFileWriteStore and JsonRestStore do not work with the same structures.
IFWS uses arrays only whereas JRS uses a mix of arrays / objects.
I'm afraid you will have to manage the relationships by hand. For example, when clicking on validate after editing the kids, you will loop through them, then update the JRS, then JRS.save()