gpt4 book ai didi

javascript - 来自后端的 JSON 值的动态模型名称

转载 作者:行者123 更新时间:2023-11-28 04:41:49 24 4
gpt4 key购买 nike

我有一个来自后端的 Json,如下所示:

var infoArray = [
{
"field" : "text",
"placeholder" : "Name",
"modelName" : "userName"
},{
"field" : "date",
"placeholder" : "DOB",
"modelName" : "userDob"
},{
"field" : "text",
"placeholder" : "Location",
"modelName" : "userLocation"
}
];

It's already set that there can be at most 10 text fields and 4 date fields i can get.

由于 ModelName 来自后端,所以我尝试将其放入简单的 ng-repeat 中,但这似乎不起作用 Here is Plnkr Link

Indeed i found one solution by myself and the code seems to be bulky for that.

Here is plnkr Link

And one more thing i have to consider is that i have to use the modelName to get the values from the user and then sent it back.

有人可以建议优化的解决方案或修改我的代码吗?谢谢!

最佳答案

你的尝试几乎是正确的。只需要删除ng-model中的大括号

 <div ng-repeat="info in infoArray">
<input type="{{info.field}}" placeholder="{{info.placeholder}}" ng-model="info.modelName" ng-init="callFunc(info)" />
</div>

Demo

关于javascript - 来自后端的 JSON 值的动态模型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43693973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com