Opened 9 years ago
Last modified 3 years ago
#15660 reopened feature
dojo/store/Memory: make put() support "parent" and "before" options
Reported by: | bill | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | high | Milestone: | 1.14 |
Component: | Data | Version: | 1.7.3 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | #15661 |
Description (last modified by )
As the doc explains, stores can support inserting an item as a specific child of another item (as opposed to the last child. dojo/store/Memory doesn't support this. But it's needed for dijit/Tree. (Currently the DnD example of Tree, dijit/tests/tree/test_tree_Dnd.html, is running off of ItemFileWriteStore due to this limitation.)
A colleague (Anthony Erwin, IBM, CCLA) created a subclass of Memory to support it, perhaps you can use that code as a base. Obviously you would need tests too.
// Need to override put to support DnD and node ordering put: function (object, options){ if (options) { // Per tree example online: // To support DnD, the store must support put(child, {parent: parent}). // Since memory store doesn't, we hack it. // Since our store is relational, that just amounts to setting child.parent // to the parent's id. if (options.parent){ object.parent = options.parent.id; //Another hack to cause items moved into a new parent to show up as the //last child of the parent if (!options.before) { this .remove(object.id); } } // What the examples don't tell you is that to support betweenThreshold on the tree // (and support setting the order of nodes), we also need to deal with the "before" // attribute (passed in by model's newItem and pasteItem implementations). So, hacking that // in as well. if (options.before) { data = this .data; index = this .index, idProperty = this .idProperty; var id = object[idProperty] = (options && "id" in options) ? options.id : idProperty in object ? object[idProperty] : Math.random(); if (id in index){ //Remove the object from its current position this .remove(id); } //Insert/add it in right position index = this .index; //there's a re-index after the remove operation var beforeRefId = options.before.id; if (beforeRefId in index){ //carve out a spot for the new item data.splice(index[beforeRefId], 0, object); // now we have to reindex this .setData(data); } } } return this .inherited(arguments); }
Attachments (3)
Change History (12)
comment:1 Changed 9 years ago by
Blocking: | 15661 added |
---|
comment:2 Changed 9 years ago by
Description: | modified (diff) |
---|---|
Milestone: | tbd → 2.0 |
comment:3 Changed 7 years ago by
I added a patch. I do not update dijit/tests/tree/test_tree_Dnd.html. But I tested a memory-based Dnd tree with the new memory code locally and it works well.
Changed 7 years ago by
Attachment: | test_memory.patch added |
---|
comment:5 Changed 7 years ago by
Is this patch reflects only one approach when children knows about their parent? In my case some of objects has "children" property, but children doesn't know about parents.
comment:6 Changed 5 years ago by
Milestone: | 2.0 → 1.11 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
This is handed in dstore ( http://dstorejs.io/ ), the successor of dojo/store.
comment:7 Changed 4 years ago by
Milestone: | 1.11 → 1.12 |
---|---|
Priority: | undecided → high |
Resolution: | fixed |
Status: | closed → reopened |
comment:8 Changed 4 years ago by
Milestone: | 1.12 → 1.13 |
---|
Ticket planning... move current 1.12 tickets out to 1.13 that likely won't get fixed in 1.12.
comment:9 Changed 3 years ago by
Milestone: | 1.13 → 1.14 |
---|
Marking this for 2.0 since we will need it by then for Tree, since dojo/data is presumably going away.