My Following code is working fine but I have to hard code each element separately.
How to display each element (myElement as shown below) in Json object using $.each without providing every element separately.
function getList() {
$.getJSON("MY_CONTROLLER_URL",function(data){
if(data) {
var json_data;
$.each(data, function(i,myObject){
debugger;
json_data = ''+myObject.myElement+' ';
$(json_data).appendTo('#list-data');
});
}
});
Answer
var x = {
a: "Hello",
b: "World"
}
Then you can use
Object.keys(x) // => ["a", "b"]
[].forEach.call(Object.keys(x), function(inst){
console.log(x[inst]); // Will output a and then b
});
No comments:
Post a Comment