Extjs存储到数组获取对象属性

Extjs Store to Array get object property

本文关键字:取对象 属性 获取 数组 存储 Extjs      更新时间:2023-09-26

我正在制作一个拉力应用程序,我使用商店从投资组合/功能模型中提取数据。这是预期的工作。我想将侦听器返回的内容转换为数组我面临的问题是数组只是返回对象,我需要从对象属性的数据。数组的结果如下所示

["F1870", "25343 -某些项目名称",",Object, Object, Mon Apr 27 2015 02:00:00 GMT-0400(东部夏令时)]

第一个对象值应该是John Smith。John Smith位于

属性中

对象

0:"F1870"

1: "25343 - Some "

2: "

3:对象

_p: "0"_ref: "blah Balh"

_refObjectName: "John Smith"

_refObjectUUID: "blah blah"

_type:

Owner[_refObjectName]我需要得到什么,我迷路了。

******编辑添加更多细节****存储返回值如下所示

数据:对象

FormattedID: F1223

名称:Some project

描述:Blah Blah Blah

主:对象_p:

 _ref:
 _refObjectName: John Smith 
我需要数组返回

FormattedID: F1223

名称:Some project

描述:Blah Blah Blah

船主:John Smith

这是我到目前为止的代码。

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    launch: function () {
        console.log("App Launched")   
   //App Calls the portfolio feature data store
   this._getfeaturedatastore();
    },
    //Get the portfolio feature data from Rally 
    _getfeaturedatastore: function(){   
       var getfeaturedata = Ext.create('Rally.data.wsapi.Store', {
    model: 'PortfolioItem/Feature',
    autoLoad: true,
   //Create Fillter for the Store 
     filters: [
        {
            property: 'State.Name',
        
            value: 'Story Definition',
        }
    ],
    listeners: {
        load: function(getfeaturedatastore, getfeaturedatadata, success) {
        console.log("Got Feature Data Woot",getfeaturedatastore, getfeaturedatadata, success)    
        this._displayFeatureCard(getfeaturedata);
        },
        
         scope: this
    },
    fetch: ['State', 'Name', 'Description', 'Owner', 'Parent','PlannedStartDate','FormattedID','Tags']
});
    },
    
    _displayFeatureCard: function(getfeaturedata){
        var MAX_NAME_LEN = 115;
        var name,i,theMarkup, description, owner, parent, plannedstartdate, formattedid;
    
          
    var data =[];
    getfeaturedata.each(function(record){
    var recordArray = [
        record.get("FormattedID"),
        record.get("Name"),
        record.get("Description"),
        record.get("Owner"),
        record.get("Parent"),
        record.get("PlannedStartDate")
        
        ];
        data.push(recordArray);
        console.log(recordArray)
    });
    

关于您可以访问哪些数据以及如何访问这些数据的线索,可以通过WebServices文档访问(通过您的头像访问右上角的帮助链接)

任何保存在Rally数据库中的工件都可以返回给您:字符串,数字,对象或(对象的)集合。

对于投资组合项目的"所有者",它是一个User类型的对象。对象的内容描述了所有者,而不仅仅提供了名称。因为它是一个对象,你必须执行record.get("Owner")来获取对象,然后执行record.get("Owner")。Name获取所有者的名称。

FormattedID作为字符串返回,所以您只需要执行record.get("FormattedID")来获取文本。

您可以使用gerange方法从存储中获取所有记录,然后使用getData方法从每个记录中获取所有数据。

listeners: {
    load: function(store) {
        var data = _.map(store.getRange(), function(record) {
            return record.getData();
        });
        var feature1 = data[0],
            ownerName = feature1.Owner._refObjectName;
    }
}

这个例子还使用lodash map函数来减少必要的代码行数。此时,data将是一个普通的老式javascript对象数组,其中包含来自存储的数据。