Extjs Store to Array get object property

2.7k views Asked by At

I am working on a Rally App I am using a Store to pull data from the Portfolio/Feature Modle. This is working as expected. I want to convert what the lisener returns to an arry The issue I am facing is the array is just retruning the Object and I need the data from the Object Property. Results of the array look like this

["F1870", "25343 - some project name ", "", Object, Object, Mon Apr 27 2015 02:00:00 GMT-0400 (Eastern Daylight Time)]

The first Objects Value should be John Smith. John Smith Sits in the propery of the

Object

0: "F1870"

1: "25343 - Some "

2: ""

3: Object

_p: "0"_ref: "blah Balh"

_refObjectName: "John Smith"

_refObjectUUID: "blah blah"

_type:

Owner[_refObjectName] what i need to get and i am lost.

******Edited To add more detials**** The store returns values look like this

data: Object

FormattedID:F1223

Name: Some project

Description: Blah blah blah

Owner: Object _p:

 _ref:

 _refObjectName: John Smith 

I need the array to return

FormattedID:F1223

Name: Some project

Description: Blah blah blah

Owner: John Smith

Here is the code i have so far.

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)
    });
    

2

There are 2 answers

1
NotApplicable On BEST ANSWER

The clues as to what data you have access to and how to do it, is accessible via the WebServices documentation ( go to the help link accessible via your avatar in the top right hand corner)

Any artifact that is held in the Rally database can come back to you looking like: a string, a number, an object or a collection (of objects).

In the case of the 'Owner' of a portfolio item, it is an object of type User. The contents of the object describe the owner and not just providing the name. As it is an object, you have to do record.get("Owner") to get the object and then do record.get("Owner").Name to get the name of the owner.

FormattedID comes back as a string, so you just need to do record.get("FormattedID") to get the text.

2
Kyle Morse On

You can get all the records from the store using the getRange method and then get all the data from each record using the getData method.

listeners: {
    load: function(store) {
        var data = _.map(store.getRange(), function(record) {
            return record.getData();
        });

        var feature1 = data[0],
            ownerName = feature1.Owner._refObjectName;
    }
}

This example also uses the lodash map function to reduce the lines of code necessary. At this point data will be an array of plain old javascript objects with the data from the store.