1

当我创建 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 条记录。

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

4

1 回答 1

0

I think the best way is to process the data via two Rally.data.WsapiDataStore's. You'll need to chain the listeners for the two stores together in order to properly handle the asynchronous loads. Here's an example that illustrates the process:

<!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>
于 2013-01-31T23:09:34.813 回答