/ / Come modificare il valore predefinito per ObjectStoreModel in Dojo? - javascript, dojo

Come cambiare il valore di default per ObjectStoreModel in Dojo? - javascript, dojo

Sto usando Dojo ObjectStoreModel per un widget dijit / albero. Ho bisogno di configurare ObjectStoreModel utilizzare la proprietà denominata parent_id invece del valore predefinito parent al fine di abbinare la mia struttura dati.

Qualche idea su come impostare questa configurazione?

   var data = [
{
id: "world",
name: "The earth",
type: "planet",
population: "6 billion"
},
{
id: "EG",
name: "Egypt",
type: "country",
parent_id: "AF" // does not work if property is called parent_id, only parent by default
},
{
id: "Nairobi",
name: "Nairobi",
type: "city",
parent_id: "KE"
},
{
id: "Mombasa",
name: "Mombasa",
type: "city",
parent_id: "KE"
},
{
id: "SD",
name: "Sudan",
type: "country",
parent_id: "AF"
},

];


var myStore = new Memory({
data: data,
getChildren: function (object) {
return this.query({ parent: object.id });
}
});

// Create the model
var myModel = new ObjectStoreModel({
store: myStore,
query: { id: "0" }
});


// Create the Tree.
var tree = new Tree({
model: myModel
});
tree.placeAt(this.domNode);
tree.startup();

risposte:

0 per risposta № 1

Ho trovato la soluzione al mio problema

http://dojotoolkit.org/reference-guide/1.10/dijit/tree/ObjectStoreModel.html

Affermando: The dojo.store must implement it’s own getChildren() method.

Quindi con questo script di modifica funziona bene.

var myStore = new Memory({
data: data,
getChildren: function (object) {
return this.query({ parent_id: object.id });
}
});