extjs在treestore中检索子节点

时间:2013-05-26 13:39:53

标签: extjs tree nodes

我正在加载一个树库,获取根节点,然后尝试迭代子节点。从我观察到的,在我看来,树被加载到商店,我能够得到根,当我在控制台中扩展根我能够看到孩子,但当我尝试访问孩子从ExtJS我收到错误。

非常感谢任何帮助。非常感谢你提前。


    var ts = this.getStore('QaireTreeStore');

    console.log("--- ts:");
    console.log(ts);

    var p = ts.getProxy();

    console.log("--- p:");
    console.log(p);

    p.extraParams = {};

    p.setExtraParam('prgmCode','arg1');
    p.setExtraParam('qaireCode','arg2');

    ts.removeAll();
    ts.load();

    var rn = ts.getRootNode();

    console.log("--- rn:");
    console.log(rn);


    console.log("--- isRoot");
    console.log(rn.isRoot());

    rn.eachChild(function(n) {
        console.log('-- n:');
        console.log(n);
    });

    console.log("--- firstChild:");
    console.log(rn.firstChild);


    console.log("--- childNodes:");
    console.log(rn.childNodes);

    console.log("--- getChildAt 0:");
    console.log(rn.getChildAt(0));

在“--- rn:”下我扩展了“childNodes”和“constructor”以显示数据存在。输出显示为:     

--- ts: SrvyController.js:71
    constructor {autoLoad: false, model: function, storeId: "QaireTreeStore", proxy: constructor, fields: Array[1]…}
     SrvyController.js:72
    --- p: SrvyController.js:76
    constructor {type: "ajax", api: Object, reader: constructor, model: function, hasListeners: HasListeners…}
     SrvyController.js:77
    --- rn: SrvyController.js:89
    constructor {phantom: false, internalId: "ext-record-1", raw: Object, data: Object, modified: Object…}
    childNodes: Array[1]
    0: constructor
    childNodes: Array[9]
    data: Object
    dirty: false
    editing: false
    events: Object
    firstChild: constructor
    hasListeners: HasListeners
    id: "IHA.model.QaireModel-48"
    internalId: 48
    lastChild: constructor
    modified: Object
    nextSibling: null
    parentNode: constructor
    phantom: false
    previousSibling: null
    raw: Object
    stores: Array[0]
    proto: TemplateClass
    length: 1
    proto: Array[0]
    data: Object
    dirty: false
    editing: false
    events: Object
    firstChild: constructor
    hasListeners: HasListeners
    id: "IHA.model.QaireModel-ext-record-1"
    internalId: "ext-record-1"
    lastChild: constructor
    modified: Object
    nextSibling: null
    parentNode: null
    phantom: false
    previousSibling: null
    raw: Object
    stores: Array[0]
    proto: TemplateClass
     SrvyController.js:90
    --- isRoot SrvyController.js:93
    true SrvyController.js:94
    --- firstChild: SrvyController.js:101
    null SrvyController.js:102
    --- childNodes: SrvyController.js:105
    [] SrvyController.js:106
    --- getChildAt 0: SrvyController.js:108
    undefined

1 个答案:

答案 0 :(得分:0)

不确定这是否会解决您的问题,但由于您使用的是AJAX代理,因此您应该在商店的监听器中进行处理。

ts.on('load', function(store, records) {
   var rn = ts.getRootNode();
   //do your processing here
});