gpt4 book ai didi

javascript - Angular 使用对象的数组值

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

所以我尝试通过数组中的值设置一些对象值。

$scope.ngmodelfield = {};
$scope.categories = [{
cat: "Cat 1a",
translationTag: "OccupationalSafety"
}, {
cat: "Cat 1b",
translationTag: "IndustrialSafety"
}, {
cat: "Cat 2",
translationTag: "Growth"
}, {
cat: "Cat 3",
translationTag: "Modifications"
}, {
cat: "Cat 4",
translationTag: "Maintenance"
}, {
cat: "Cat 5",
translationTag: "Renewals"
}, {
cat: "Cat 6",
translationTag: "Environment"
}, {
cat: "Cat 7",
translationTag: "IT"
}, {
cat: "Cat 8",
translationTag: "ResearchAndDevelopment"
}, {
cat: "Cat 9",
translationTag: "LegalRequirements"
}];

所以我按以下方式迭代对象:

  <div class="row" ng-repeat="cat in categories track by $index">
<div class="col s12">
<div class="col s4">
{{cat.cat}} - {{cat.translationTag}}
</div>
<div class="col s8">
<textarea ng-model="ngmodelfield.[cat.translationTag]" class="materialize-textarea"></textarea>
</div>
</div>
</div>

现在我想将第一个文本区域链接到 ngmodelfield.OccupationalSafety,第二个文本区域链接到 ngmodelfield.InduscialSafety,依此类推。

但这似乎不起作用,如下所示:http://plnkr.co/edit/WKCLjzmLy1IrwEmQPMRH?p=preview

最佳答案

只需更改:

<div class="col s8">
<textarea ng-model="ngmodelfield.[cat.translationTag]" class="materialize-textarea">{{cat.cat}}</textarea>
</div>

至:

<div class="col s8">
<textarea ng-model="ngmodelfield[cat.translationTag]" class="materialize-textarea">{{cat.cat}}</textarea>
</div>

也就是说,删除 ng-model="ngmodelfield.[cat.translationTag]" 中的点。

关于javascript - Angular 使用对象的数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32586915/

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