這裏是發生了什麼:
你清楚奇怪的是商店:(我會使用storePersonas.removeAll()
)
storePersonas.loadData([],false);
你火的asynchronious請求加載數據:
storePersonas.load({
params:{
'NIPersona':NIPersona
},
callback: compruebaExitoPersonas
});
(除非您已經實例化它高於在代碼R)創建一個全局變量= 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;
});
過了一會兒,你得到了你assynchronious答案回!
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!');
}
}
});
來源
2013-12-23 08:59:30
VDP
我可以同步存儲與這個工作? 問候和感謝.... –
@ user3001143我更新了我的答案;) – VDP