javascript - 无法从 Rally wsapidatastore 访问数据

标签 javascript rally

当我创建 WsapiDataStore 时,store.data.items 和 store.data.keys 返回空数组,尽管我在执行 console.log(store.data) 时能够看到键和项目

store = Ext.create('Rally.data.WsapiDataStore', {
    model: 'Defect',
    context: {
        project: '/project/xxxxxx'
    },
    autoLoad: true,
    fetch: ['Rank', 'FormattedID', 'Name']
});

console.log(store.data)的输出:

constructor {items: Array[0], map: Object, keys: Array[0], length: 0, allowFunctions:   false…}
    allowFunctions: false
    events: Object
    generation: 8
    getKey: function (record) {
    hasListeners: HasListeners
    items: Array[7]
    keys: Array[7]
    length: 7
    map: Object
    sorters: constructor
    __proto__: TemplateClass

请注意第一行如何显示“items: Array[0]”和“keys: Array[0]”,但展开时它显示“items: Array[7]”和“keys: Array[7]”。当我进一步展开时,我还可以看到 7 条记录。

当我添加加载监听器并从监听器函数访问数据时,一切都会按预期工作(但我不想这样做)

最佳答案

我认为最好的方法是通过两个 Rally.data.WsapiDataStore 处理数据。您需要将两个存储的监听器链接在一起,以便正确处理异步加载。下面是一个说明该过程的示例:

<!DOCTYPE html>
<html>
<head>
    <title>MultipleModelExample</title>

    <script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0p5/sdk.js"></script>

    <script type="text/javascript">
        Rally.onReady(function() {
            Ext.define('CustomApp', {
                extend: 'Rally.app.App',
                componentCls: 'app',

                // Combined Story/Defect Records
                dataRecords: null,

                launch: function() {
                    //Write app code here

                    this.dataRecords = [];

                    Rally.data.ModelFactory.getModels({
                        types: ['HierarchicalRequirement','Defect'],
                        scope: this,
                        success: function(models) {
                            this.myModels = models;

                            this.storyStore = Ext.create('Rally.data.WsapiDataStore', {
                                model: models.HierarchicalRequirement,
                                fetch: true,
                                autoLoad: true,
                                remoteSort: true,
                                sorters: [
                                    { property: 'FormattedID', direction: 'Asc' }
                                ],
                                listeners: {
                                    load: this._processStories,
                                    scope: this
                                }
                            });
                        }
                    });
                },

                _processStories: function(store, records, successful, opts) {

                    var storyRecords = [];

                    Ext.Array.each(records, function(record) {
                        //Perform custom actions with the data here
                        //Calculations, etc.
                        storyRecords.push({
                            FormattedID: record.get('FormattedID'),
                            Name: record.get('Name'),
                            Description: record.get('Description')
                        });
                    });

                    this.dataRecords = storyRecords;

                    this.defectStore = Ext.create('Rally.data.WsapiDataStore', {
                        model: this.myModels.Defect,
                        fetch: true,
                        autoLoad: true,
                        remoteSort: true,
                        sorters: [
                            { property: 'FormattedID', direction: 'Asc' }
                        ],
                        listeners: {
                            load: this._processDefects,
                            scope: this
                        }
                    });
                },

                _processDefects: function(store, records, successful, opts) {

                    var defectRecords = [];

                    Ext.Array.each(records, function(record) {
                        //Perform custom actions with the data here
                        //Calculations, etc.
                        defectRecords.push({
                            FormattedID: record.get('FormattedID'),
                            Name: record.get('Name'),
                            Description: record.get('Description')
                        });
                    });

                    var combinedRecords = defectRecords.concat(this.dataRecords);

                    this.add({
                        xtype: 'rallygrid',
                        store: Ext.create('Rally.data.custom.Store', {
                            data: combinedRecords,
                            pageSize: 25
                        }),
                        columnCfgs: [
                            {
                                text: 'FormattedID', dataIndex: 'FormattedID'
                            },
                            {
                                text: 'Name', dataIndex: 'Name', flex: 1
                            },
                            {
                                text: 'Description', dataIndex: 'Description', flex: 1
                            }
                        ]
                    });
                }

            });

            Rally.launchApp('CustomApp', {
                name: 'MultipleModelExample'
            });
        });
    </script>

    <style type="text/css">
        .app {
             /* Add app styles here */
        }
    </style>
</head>
<body></body>
</html>

关于javascript - 无法从 Rally wsapidatastore 访问数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14617302/

相关文章:

ruby - Rally Ruby API - 向 'description' 字段添加换行符

javascript - 如何在 Protractor 中定位 ng-reflect ng 类属性?错误

javascript - 使用 Express 嵌套路由器的正确/简洁方法

Rally Rest API .NET 工具包使用标签创建缺陷/用户故事

java - 我可以从 Rally 中提取报告吗(使用 Rally Rest Api 和 Java)

javascript - Javascript数组返回对象对象错误

php - 使用 javascript 获取 session

javascript - 使用 Javascript 从 Outlook 解析 msg 文件

javascript - 使用 javascript rrule.min.js 实现 RRule

testing - 如何更改 Rallys 测试文件夹状态