1

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

在上面链接的简单树形网格示例中,我添加了控制台日志以打印根节点,但它始终以null的形式出现,即使加载了用户故事。

我也遇到了 store.getTopLevelNodes() 的异常

有人可以解释一下吗?

////代码

_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)
4

1 回答 1

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 无论如何都会为您加载商店。您可能会遇到双重负担。值得检查您的网络流量以进行验证。

于 2018-02-27T20:16:50.697 回答