0

I got result like

{"ID":1022,"Type":"type1","Name":"name1","Values":[{"ID":3540,"Name":"1"},{"ID":3541,"Name":"2"},{"ID":3542,"Name":"cb"}]}

so on success i got function like this

 success: function(data) {
 $.each(data, function() {
 $('#properties').append(
 this.ID + "," +
 this.Name + "," +
 this.type + "," +
 this.values
 );
 });
 }

but "values" is another array, so how to show it?

Pointy
415k62 gold badges600 silver badges633 bronze badges
asked May 23, 2012 at 15:25

4 Answers 4

1
//get the total length of values array.
this.Values.length;
for ( var i = 0 ; i < this.Values.length; i++ ){
 var resultId= this.Values[i].ID;
 var resultName = this.Values[i].Name;
}

This works.

answered May 23, 2012 at 15:32
Sign up to request clarification or add additional context in comments.

Comments

1

I believe this.Values[0].ID should return the ID from the first element correctly.

You could also loop through each item in the array and access it in the same way.

for (var i = 0; i < this.Values.length; i++) {
 alert(this.Values[i].ID); //Show an alert for each ID.
}
answered May 23, 2012 at 15:29

1 Comment

I made a small change to use this.values[i] which should work now.
0

this.values[0].ID may work, however, I'm not completely sure. I guess there's no harm in trying, though.

answered May 23, 2012 at 15:29

Comments

0

I am not quite sure what the value of this is inside the inner-most function, but it is probably not what you want it to be. In order to pass a variable to a function when it is created, instead of when it is called, you should wrap it with another function like this:

{
 success: function(data) {
 $.each(data, (function(dat) { return function(index, value) {
 $('#properties').append(
 value.ID + "," +
 value.Name + "," +
 dat.type + "," +
 dat.values
 );
 }; ) (data));
 }
};
answered May 23, 2012 at 15:35

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.