2013-12-23 14 views
0
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」中至少有一個內容。未找到「每個」的說法,爲什麼?

的問候和感謝....

回答

1

這裏是發生了什麼:

你清楚奇怪的是商店:(我會使用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!'); 
     } 
    } 
}); 
+0

我可以同步存儲與這個工作? 問候和感謝.... –

+0

@ user3001143我更新了我的答案;) – VDP

相關問題