i want to use a dojo/data/JsonRest to display a Tree. Load from Server works fine, but if i add a new Item, the new Item is displayed on each openend node. The request is made to the server an the response looks good for me. On the Serverside i use PHP with SlimFramwork
The Javascript is as follows:
require([
"dojo/parser",
"dojo/_base/array",
"dojo/on",
"dijit/registry",
"dojo/store/JsonRest",
"dojo/store/Observable",
"dijit/Tree",
"dijit/tree/ObjectStoreModel",
"dijit/form/Button",
"dojo/domReady!"
], function(parser, array, on, registry, JsonRest, Observable, Tree, ObjectStoreModel
){
parser.parse();
var reststore = new JsonRest({
target: "Antrag/",
getChildren: function(object){
console.dir(object);
return this.query({parent: object.id});
}
});
var reststore=new Observable(reststore);
var treeModel = new ObjectStoreModel({
store: reststore,
//labelAttr: "anzeige",
query: {
jahr: 2015,
nummer: 1,
antArt: 1,
kb: 58,
antArt: 1,
tree: true
},
mayHaveChildren: function(object){
return true;
},
getLabel : function(item) {
console.dir(item);
console.log(item.typ);
if(item!=null){
//console.dir(item);
if (item.typ == "KE") {
if (item.posten == "0") {
rueckgabe = "Keine Postennr";
} else {
rueckgabe = item.posten;
}
} else if (item.typ == "KD" || item.typ == "NL" || item.typ == "ADDR") {
//console.log(item.typ+" "+item.Bezeichnung);
rueckgabe = item.Bezeichnung;
} else if (item.typ.substring(0,6)=="antrag") {
this._antrag=item;
rueckgabe = item.anzeige;
} else {
//console.log(item.typ+" "+item.anzeige);
rueckgabe = item.anzeige;
}
return rueckgabe;
}else{
return false;
}
},
});
var tree = new dijit.Tree({
model : treeModel,
autoExpand: true
}, 'treeNode');
tree.startup();
on(registry.byId('butAdd'), "click", function(e){
var selectedObject = tree.get("selectedItems")[0];
var LS={
typ: "LS",
//antrag: selectedObject.id,
//antrag: this._antrag.id,
berechnung: selectedObject.id,
neu: true,
//parent: selectedObject.id
};
reststore.put({
typ: "LS",
//antrag: selectedObject.id,
//antrag: this._antrag.id,
berechnung: selectedObject.id,
neu: true,
}, {parent: selectedObject});
})
});
All Items that are loaded at startup looks fine. Everything is at the right place.
The Request for a new Item (from Web-Developer) looks like this:
berechnung:"Rech234647"
neu:true
typ:"LS"
The response from Server is:
{"id":"LS234647_1","berechnungId":"234647","typ":"LS","parent":"Rech234647",anzeige":"Lieferschein 1"}
I don't understand why the new item is displayed under all opened Nodes. If i do a delete, all Representations of the new Node are deleted inside the Tree.
The Goal is to use an Cachestore to provide all methods for querying the store.
require([
"dojo/parser",
"dojo/_base/array",
"dojo/on",
"dijit/registry",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Observable",
"dojo/store/Cache",
"dijit/Tree",
"dijit/tree/ObjectStoreModel",
"dijit/form/Button",
"dojo/domReady!"
], function(parser, array, on, registry, JsonRest, Memory, Observable, Cache, Tree, ObjectStoreModel
){
parser.parse();
var reststore1 = new JsonRest({
target: "Antrag/",
getChildren: function(object){
console.dir(object);
return this.query({parent: object.id});
}
});
var memorystore=new Memory();
var reststore=new Observable(new Cache(reststore1, memorystore));
var treeModel = new ObjectStoreModel({
store: reststore,
query: {
jahr: 2015,
nummer: 1,
antArt: 1,
kb: 58,
antArt: 1,
tree: true
},
mayHaveChildren: function(object){
return true;
},
getLabel : function(item) {
console.dir(item);
console.log(item.typ);
if(item!=null){
if (item.typ == "KE") {
if (item.posten == "0") {
rueckgabe = "Keine Postennr";
} else {
rueckgabe = item.posten;
}
} else if (item.typ == "KD" || item.typ == "NL" || item.typ == "ADDR") {
rueckgabe = item.Bezeichnung;
} else if (item.typ.substring(0,6)=="antrag") {
this._antrag=item;
rueckgabe = item.anzeige;
} else {
rueckgabe = item.anzeige;
}
return rueckgabe;
}else{
return false;
}
},
});
var tree = new dijit.Tree({
model : treeModel,
autoExpand: true
}, 'treeNode');
tree.startup();
on(registry.byId('butAdd'), "click", function(e){
var selectedObject = tree.get("selectedItems")[0];
var LS={
typ: "LS",
berechnung: selectedObject.id,
neu: true,
};
reststore.put({
typ: "LS",
berechnung: selectedObject.id,
neu: true,
}, {parent: selectedObject});
})
});
I'll update my fiddle http://jsfiddle.net/jp14psez/31/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.