dijit.Tree
には、カスタムデータストアを使用してデータを提供するForestStoreModel
があります。それはうまくいきますが、私は、ユーザーが道場のドラッグアンドドロップ機能でトップレベルのアイテム(および最上位レベルのアイテム)を並べ替える機能を提供したいと考えています。dijitツリーに最上位のノード項目をドラッグ&ドロップで配置する方法
問題は、ForestStoreModel::pasteItem
関数がルートの子であるかどうかを確認してからnull
をTreeStoreModel::pasteItem
に渡すという問題です。渡された親項目がnullの場合TreeStoreModel
pasteItem: function(/*Item*/ childItem, /*Item*/ oldParentItem, /*Item*/ newParentItem, /*Boolean*/ bCopy, /*int?*/ insertIndex){
// summary:
// Move or copy an item from one parent item to another.
// Used in drag & drop
if(oldParentItem === this.root){
if(!bCopy){
// It's onLeaveRoot()'s responsibility to modify the item so it no longer matches
// this.query... thus triggering an onChildrenChange() event to notify the Tree
// that this element is no longer a child of the root node
this.onLeaveRoot(childItem);
}
}
dijit.tree.TreeStoreModel.prototype.pasteItem.call(this, childItem,
oldParentItem === this.root ? null : oldParentItem,
newParentItem === this.root ? null : newParentItem,
bCopy,
insertIndex
);
if(newParentItem === this.root){
// It's onAddToRoot()'s responsibility to modify the item so it matches
// this.query... thus triggering an onChildrenChange() event to notify the Tree
// that this element is now a child of the root node
this.onAddToRoot(childItem);
}
}
は、基礎となるデータストアを更新しないとonLeaveRoot
とonAddToRoot
イベントはinsertIndex
に通過しないので、私はのように思える私のデータストアを(更新するためにそれらを使用することはできませんとにかく少し後ろになるだろう)。私が唯一の現実的な選択肢は、私は互換性のあるデータストアオブジェクトに合成$root$
項目を設定し、ForestStoreModel
がTreeStoreModel
に至るまで、変更せず、それを渡すことができるようにすることを可能にするためにForestStoreModel
を拡張することだと思います。この時点で
。
この問題には他の方法がありますか?
更新
最終的な解決策を提案よりもさらに簡単であることが判明しました。私のForestStoreModel
は、実際にdojo 1.6 ObjectStoreをデータソースとして使用しているので、すでにカスタムクラスです。オブジェクトストアput
メソッドのoptions
引数に目的のインデックスを渡すことができます。
pasteItem: function(/*Item*/ childItem, /*Item*/ oldParentItem, /*Item*/ newParentItem, /*Boolean*/ bCopy, /*int?*/ insertIndex){
// Handle drag & drop at the root level
if (oldParentItem === this.root && newParentItem === this.root){
this.store.put(childItem, { index: insertIndex });
}
this.inherited(arguments);
}
このアップデートは回答であったはずです。 – DanMan