1

I am storing field value (Sales, ProductName) from json in an array named 'data[]' and 'name[]'. Below is the code which works fine.

function onCompletedCallback(response, eventArgs) {

        var chartlist = eval("(" + response.get_responseData() + ")");
        var markup = " ";

        //Display the raw JSON response
        markup += response.get_responseData();
       // alert(markup);

      var jsonData=jQuery.parseJSON(markup);   
// alert(jsonData);

//declaring arrays
var name = [];
var data = [];

$.each(jsonData.d.results, function (index, value) {


  data.push(value.Sales);
  name.push(value.ProductName);

    });
}

Now what I want to pass field values from dropdown(ddlxField) in my UI, which holds all the fieldname of the list and pass it to json object while pushing data in 'name' array. For now am choosing 'ProductName' form dropdown, i.e, xName=ProductName

var xName = document.getElementById("ddlxField").value;
 $.each(jsonData.d.results, function (index, value) {

  data.push(value.Sales);
  name.push(value.xName); // xname value= ProductName

    });

But after execution, xName is coming out to be undefined. can anyone suggest what else can be done or where am going wrong?

0

1 Answer 1

3

Use value[xName] instead of value.xName.

The [] syntax need a string for key, just like xName.

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

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.