0

I have been stuck with this issue for a long time now..:(

I have an object that im trying to read the sub-array from. below is the look of the JSON format. im trying to extract the qaccess values from it, as like qaccess.0.product, qaccess.1.product.

  "qaccess": [
    {
      "product": "wm.od.prod.nsr",
      "status": "enabled",
      "roleIdentifiers": [

      ],
      "permissionIdentifiers": [

      ]
    },
    {
      "product": "gp.od.dev.nsr",
      "status": "Active",
      "roleIdentifiers": [

      ],
      "permissionIdentifiers": [

      ]
    }
  ]

And below if what my code looks like:

addColumn: function(oObj, type, val){
    //however i checked now, and found that the `oObj, type, val` returns 'null' and hence i am unable to use the addColumn function anymore. that is one problem i faced and hence took up another approach of adding the function in the `mDataProp`, like the one shown in the EDIT part.

        propertySize = oObj.qaccess.length;

        for(i=0; i<propertySize; i=i+1){
        { 
        "mDataProp": "qaccess." + i + ".product",


            "sTitle": "Status",
            "sClass": "_status",
            "sWidth": "10%",
           }
        }


        });
})
        this.columns.push(col);
        // return the index of the new column
        return this.columns;


    },

To get multiple values of the object, can i write it in for loop as shown above? Ex:

for(i=0; i<propertySize; i=i+1){ { "mDataProp": "qaccess." + i + ".product"}}.

EDIT:

I also tried doing something like this :

columns: [
 {"mRender": function(obj, val, data){

    propertySize =  data.qaccess.length;
           for(i=0; i<propertySize; i=i+1){
            col= {
                "mDataProp": "qaccess." + i + ".product",
                sTitle: "Account Name", sClass: "_accountName", sWidth: "25%"
            }
        }       
  }
 }]

The data above returns: out of which im trying to get the value of 'qaccess[0].product' and 'qaccess[1].product' in my table.

.   qaccess: Array[2]
.    0: Object
.       permissionIdentifiers: Array[0]
.       product: "wm.od.prod.nsr"
.       roleIdentifiers: Array[0]
.       status: "enabled"
.   1: Object
⁃       permissionIdentifiers: Array[0]
⁃       product: "gp.od.dev.nsr"
⁃       roleIdentifiers: Array[0]
⁃       status: "Active"

how can i achieve the values of the qaccess array values.

Thanks.

3 Answers 3

1

I put together a JSFiddle with an example of how to access the data: http://jsfiddle.net/a3cc8vat/

Bottom line is that you use

obj.qaccess[1].product

Incorrect:

obj.qaccess.1.product

And you should not use quotes around the name. You for loop should be more like

for(i=0; i<propertySize; i=i+1){
        { 
        "mDataProp": this.qaccess[i].product,

Not sure if the this is needed for your example because it's hard to tell what the context is based on your code snippet.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks, for providing this idea. however, it works only when i have a single Object. when there are multiple Objects, it provides only the last object.qaccess details.any clue on how to handle multiple objects??? Thanks
Also the 'this.columns.push(col);' keeps adding columns to the table, if not refreshed. Is there any way i can avoid that?? Thnks
I am having trouble understanding what you want?? Also you have referred to this.columns but columns is not in your code sample.
I'm pretty sure I can answer your question if I can just get more details of what you are really needing.
0

You can get value using the code below:

"mDataProp": oObj["qaccess"][i]["product"]

Comments

0

Found the answer:

                mData: null,
                sTitle: "Products",
                sWidth: "10%",
                sClass: "_status",
                mRender: function (data, type, obj) {
                    var returnVal = "";
                  _.each(obj.qaccess, function(item, index){
                    returnVal += "<span class='_status'>" + item["product"] + "</span>";
                  });
                  return returnVal;

                }

This returned me: val1 val2.

Thanks @jwatts1980 for the help, however i need a to add commas between these two values. some columns may have more than one values, if so i need to add comma so that its:

val1,val2.

Any help???

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.