can someone help me displaying that JSON array
{"contenusModeleCarte"{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier commentaire pour le premier modele de carte","dessertCarte0":"pommes au four "},{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier commentaire pour le premier modele de carte","dessertCarte1":"salade de fruits"},{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier commentaire pour le premier modele de carte","dessertCarte2":"bananes"}]}
into form inputs.
When I try to do it via this code
$.each(dataModeleCarte.contenusModeleCarte, function(i,contenusModeleCarte){
if(co开发者_开发知识库ntenusModeleCarte.dessertCarte+i == null){
$("#edit-field-dessert-carte-"+ i +"-value-field-dessert-value").val('');
}else{
$("#edit-field-dessert-carte-"+ i +"-value-field-dessert-value").val(contenusModeleCarte.dessertCarte);
}
});
I only get as a result :
[object Object]undefined
any help would be greatly appreciated.
Thx
Your "dessertCarte" in the JSON has the numbers 0, 1, 2, ... after it, so it can't find a contenusModeleCarte.dessertCarte
You need to append the index i
after "dessertCarte":
.val(contenusModeleCarte["dessertCarte" + i]);
Is that the entire JSON string? If it is, one issue is you are missing the first colon and square bracket. It should read:
{"contenusModeleCarte":[{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier commentaire pour le premier modele de carte","dessertCarte0":"pommes au four "},{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier commentaire pour le premier modele de carte","dessertCarte1":"salade de fruits"},{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier commentaire pour le premier modele de carte","dessertCarte2":"bananes"}]}
精彩评论