storePersonas.loadData([],false);
storePersonas.load({params:{'NIPersona':NIPersona}, callback: compruebaExitoPersonas});
p=0;
storePersonas.each(function(rec) {
persona=rec.get('LIT_PERSONA');
console.log(persona+" indice p: "+p);
treeNode.getChildAt(v).getChildAt(0).appendChild({
id: "p"+p,
text: persona,
iconCls: 'persona',
leaf: true
});
p=p+1;
});
没有输入“each”语句,我在浏览器chrome中看到,如果你在“LIT_PERSONA”中至少有一个内容。
问候和感谢....
答案 0 :(得分:1)
以下是发生的事情:
你以一种奇怪的方式清理商店:(我会使用storePersonas.removeAll()
)
storePersonas.loadData([],false);
您发出异步请求以加载数据:
storePersonas.load({
params:{
'NIPersona':NIPersona
},
callback: compruebaExitoPersonas
});
(除非您在代码中将其实例化得更高),否则您将创建一个全局变量= 0
p=0;
你迭代一个空的商店(导致踩到它)
storePersonas.each(function(rec) {
persona=rec.get('LIT_PERSONA');
console.log(persona+" indice p: "+p);
treeNode.getChildAt(v).getChildAt(0).appendChild({
id: "p"+p,
text: persona,
iconCls: 'persona',
leaf: true
});
p=p+1;
});
过了一会儿,你得到了同步的回答!
compruebaExitoPersonas()
被调用,您的数据现在就在商店中了!
<强> UDPATE 强>
您可以这样做:
var addChildNodes = function(store){
var node = treeNode.getChildAt(v);
node.removeAll(); //remove all childNodes before adding them all again (don't want doubles, do you?)
store.each(function(rec, p) {
var persona = rec.get('LIT_PERSONA');
console.log(persona + " indice p: " + p);
node.getChildAt(0).appendChild({
id: "p" + p,
text: persona,
iconCls: 'persona',
leaf: true
});
});
}
storePersonas.removeAll();
storePersonas.load({
params:{
NIPersona: NIPersona
},
callback: function(records, operation, success){
if(success){
addChildNodes(this); //this refers to the store
compruebaExitoPersonas.apply(this, arguments); //calling the provided callback with the scope (this) and all the arguments
} else {
alert('ajax call failed!');
}
}
});