[object Object]输入表单上未定义(jquery+json+php)

发布于 2024-10-08 02:58:51 字数 963 浏览 3 评论 0原文

有人可以帮我显示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染柒℉ 2024-10-15 02:58:51

JSON 中的“dessertCarte”后面有数字 0、1、2、...,因此它找不到 contenusModeleCarte.dessertCarte

您需要附加索引 i< /code> 在“dessertCarte”之后:

 .val(contenusModeleCarte["dessertCarte" + i]);

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]);
情感失落者 2024-10-15 02:58:51

这是整个 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":"香蕉"}]}

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"}]}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文