Seven price
asked on
Styling Json with Jquery
I hav Json value that has multiple values separated by a comma, Is there a way to have that rendered in the dom as a selection dropdown input.
$.getJSON('@Url.Action("my", "Home")', function(result) {
var ddl = $('#MyList');
ddl.empty();
$(result).each(function (i, item) {
alert(this.Nome);
ddl.append(
$('<option/>', {
value: this.Id
}).html(this.Nome)
);
});
});
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is not really the problem or the solution but it is coming from the controller
If that's the case there's no point closing the question.
It could be a simple matter of what type of object is being returned to you in the json call. I don't have access to that and would need your feedback.
Can you tell me what the structure of the "result" object is? using "console.log(result) or console.dir(result)" will output the contents of the variable to the console (press F12 to get developer tools up.
It could be a simple matter of what type of object is being returned to you in the json call. I don't have access to that and would need your feedback.
Can you tell me what the structure of the "result" object is? using "console.log(result) or console.dir(result)" will output the contents of the variable to the console (press F12 to get developer tools up.
ASKER
Name
[Object { Selected=false, Text="12345", Value=null}
0
Object { Selected=false, Text="56789", Value=null}
1
Object { Selected=false, Text="987665", Value=null}
2
Object { Selected=false, Text="345454", Value=null}
3
Object { Selected=false, Text="232323", Value=null}
Ok, so it's returning an array of records with the following properties: Selected, Text and Value. However there isn't a value "separated by commas". What data are you expecting?
http://jsbin.com/ugUmANe/1/edit
$(myjson).each(function (i, item) {
alert(this.Text);
ddl.append(
$('<option/>', {
value: this.Id
}).html(this.Text)
);
});
ASKER
it worked. Yes thanks. I will correct the points for the correct answer
Thanks, appreciate it
ASKER