拉力treestore根节点

时间:2018-02-20 22:49:01

标签: rally code-rally

https://help.rallydev.com/apps/2.1/doc/#!/example/simple-tree-grid

在上面链接的Simple Tree Grid示例中,我添加了控制台日志来打印根节点,但它总是以 null 的形式出现,即使用户故事已加载。

我也为store.getTopLevelNodes()

获取异常

有人可以解释一下吗?

//// CODE

_onStoreBuilt: function(store) {
                console.log('root node ', store.getRootNode());
                console.log('_getStoreTypePaths ', store._getStoreTypePaths());
                console.log('getTotalCount ', store.getTotalCount());
                console.log('getTopLevelNodes ', store.getTopLevelNodes());
                    this.add({...

///例外

 root node  null
_getStoreTypePaths  (4) ["hierarchicalrequirement", "defect", "task", "testcase"]
getTotalCount  undefined
sdk.js:65 Error: success callback for Deferred transformed result of Deferred transformed result of Deferred transformed result of Deferred threw: TypeError: Cannot read property 'childNodes' of null
    at constructor._treeWalkingEach (VM900 sdk.js:formatted:98557)
    at constructor.each (VM900 sdk.js:formatted:98554)
    at constructor.getTopLevelNodes (VM900 sdk.js:formatted:98292)
    at constructor._onStoreBuilt ()
    at VM900 sdk.js:formatted:67457
    at constructor.notify (VM900 sdk.js:formatted:67506)
    at constructor.register (VM900 sdk.js:formatted:67492)
    at constructor.then (VM900 sdk.js:formatted:67391)
    at constructor.then (VM900 sdk.js:formatted:67330)

1 个答案:

答案 0 :(得分:0)

该异常在gettopLevelNodes()调用中爆炸。我想你是想过早地执行所有这些代码。该商店在建造时尚未装载。它可能正在加载过程中,因为在该示例中,商店配置了autoLoad: true。您需要为load事件添加一个侦听器。一旦加载了,那么你应该能够获得根节点并遍历树。

Ext.create('Rally.data.wsapi.TreeStoreBuilder').build({
    models: ['userstory'],
    autoLoad: true,
    enableHierarchy: true,
    listeners: {
       load: function(store) {
           console.log('root node ', store.getRootNode());
           console.log('_getStoreTypePaths ', store._getStoreTypePaths());
           console.log('getTotalCount ', store.getTotalCount());
           console.log('getTopLevelNodes ', store.getTopLevelNodes());
       },
       scope: this
    }
}).then({
    success: this._onStoreBuilt,
    scope: this
});

你也可以不需要使用autoLoad:true,因为我认为treegrid无论如何都会为你加载商店。您可能会获得双重负载。值得检查您的网络流量以进行验证。