[object Object]输入表单上未定义(jquery+json+php)
有人可以帮我显示 JSON 数组吗
{"contenusModeleCarte"{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier 总理模型评论 carte","dessertCarte0":"四个土豆泥 "},{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier 总理模型评论 carte","dessertCarte1":"沙拉 水果"},{"idmodele":"65","modeleName":"","typerepas":null,"commentairesModeleCarte":"premier 总理模型评论 carte","dessertCarte2":"香蕉"}]}
到表单输入中。
当我尝试通过此代码执行此操作时,
$.each(dataModeleCarte.contenusModeleCarte, function(i,contenusModeleCarte){
if(contenusModeleCarte.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);
}
});
我只得到结果:
[对象对象]未定义
任何帮助将不胜感激。
谢谢
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(contenusModeleCarte.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JSON 中的“dessertCarte”后面有数字 0、1、2、...,因此它找不到
contenusModeleCarte.dessertCarte
您需要附加索引
i< /code> 在“dessertCarte”之后:
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":这是整个 JSON 字符串吗?如果是,一个问题是您缺少第一个冒号和方括号。它应该是:
Is that the entire JSON string? If it is, one issue is you are missing the first colon and square bracket. It should read: