/ / Wie ändere ich den Standardwert für ObjectStoreModel in Dojo? - Javascript, Dojo

Wie ändere ich den Standardwert für ObjectStoreModel in Dojo? - Javascript, Dojo

Ich benutze Dojo ObjectStoreModel für ein Dijit / Tree Widget. Ich muss konfigurieren ObjectStoreModel benannte Eigenschaft verwenden parent_id anstelle der Standardeinstellung parent um meine Datenstruktur anzupassen.

Irgendeine Idee, wie man diese Konfiguration einstellt?

   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();

Antworten:

0 für die Antwort № 1

Ich habe die Lösung für mein Problem gefunden

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

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

Also mit diesem Bearbeitungsskript funktioniert gut.

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