Javascript 无法从数据存储访问数据

Javascript 无法从数据存储访问数据,javascript,rally,Javascript,Rally,创建WsapiDataStore时,store.data.items和store.data.keys返回空数组,尽管在执行console.log(store.data)时可以看到键和项 console.log(store.data)的输出: 请注意,第一行显示的是“items:Array[0]”和“keys:Array[0]”,但展开后显示的是“items:Array[7]”和“keys:Array[7]”。当我进一步展开时,我也能看到这7条记录 当我添加一个load listener并从lis

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

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

请注意,第一行显示的是“items:Array[0]”和“keys:Array[0]”,但展开后显示的是“items:Array[7]”和“keys:Array[7]”。当我进一步展开时,我也能看到这7条记录


当我添加一个load listener并从listener函数访问数据时(但我不想这样做)

我认为最好的方法是通过两个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>

多重模型示例
onReady(函数(){
Ext.define('CustomApp'{
扩展:“Rally.app.app”,
组件CLS:“应用程序”,
//综合故事/缺陷记录
数据记录:空,
启动:函数(){
//在此处编写应用程序代码
this.dataRecords=[];
Rally.data.ModelFactory.getModels({
类型:['HierarchycalRequirement','Defect'],
范围:本,,
成功:功能(模型){
this.myModels=模型;
this.storyStore=Ext.create('Rally.data.WsapiDataStore'{
模型:models.hierarchycalrequirement,
是的,
自动加载:对,
remoteSort:是的,
分拣机:[
{属性:'FormattedID',方向:'Asc'}
],
听众:{
加载:这个,
范围:本
}
});
}
});
},
_processStories:函数(存储、记录、成功、选项){
var storyRecords=[];
Ext.Array.each(记录、函数(记录){
//使用此处的数据执行自定义操作
//计算等。
storyRecords.push({
FormattedID:record.get('FormattedID'),
Name:record.get('Name'),
Description:record.get('Description')
});
});
this.dataRecords=故事记录;
this.defectStore=Ext.create('Rally.data.WsapiDataStore'{
型号:this.myModels.Defect,
是的,
自动加载:对,
remoteSort:是的,
分拣机:[
{属性:'FormattedID',方向:'Asc'}
],
听众:{
加载:此。\u处理缺陷,
范围:本
}
});
},
_processDefects:功能(存储、记录、成功、选择){
风险值记录=[];
Ext.Array.each(记录、函数(记录){
//使用此处的数据执行自定义操作
//计算等。
推({
FormattedID:record.get('FormattedID'),
Name:record.get('Name'),
Description:record.get('Description')
});
});
var combinedRecords=defectRecords.concat(this.dataRecords);
这个。添加({
xtype:“rallygrid”,
store:Ext.create('Rally.data.custom.store'{
数据:合并记录,
页面大小:25
}),
专栏CFGS:[
{
文本:“FormattedID”,数据索引:“FormattedID”
},
{
文本:“名称”,数据索引:“名称”,flex:1
},
{
文本:'Description',数据索引:'Description',flex:1
}
]
});
}
});
Rally.launchApp('CustomApp'{
名称:“MultipleModelExample”
});
});
.app{
/*在此处添加应用程序样式*/
}

请记住,AppSDK是异步的,因此,如果在create语句之后立即尝试通过console.log检查存储区的元素,则可能看不到任何内容。你为什么不想要一个倾听者?代码的最终目标是什么?您可能至少需要一些事件处理来实现您的目标。如果你能在你要去的地方添加更多的上下文,也许会有一些快速的建议。我的目标是从用户故事和缺陷中查询数据,并将其显示在单个网格中。我打算对一个“UserStory”模型重复上面的代码,将其保存在一个变量中,然后从两个变量连接store.data.items。有没有更好的方法可以做到这一点?我想这种链接方法会起作用(虽然我想避免使用“全局”变量,但我想它不是一个大的de
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
<!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>