gpt4 book ai didi

javascript - 无法动态设置 ng-model

转载 作者:行者123 更新时间:2023-12-02 23:39:45 26 4
gpt4 key购买 nike

我想将数据输入到 ArrayINeed 中,因为这是我传回 API 调用的对象。目前,我未定义 "ConfirmedTrackingReferenceNumbers": Dc.ArrayINeed。我已经阅读了网上和 SO 上的多篇帖子,但未能解决该问题。

Controller

.
.
.
var Dc = this;
.
.
.
Dc.FlowerData = function () {
Dc.ArrayINeed = [];
if (Dc.Data.validate()) {
if (isTulipFlower) {
requestData = {
"FlowerId": Dc.FlowerId,
"ConfirmedTrackingReferenceNumbers": Dc.ArrayINeed
};
.
.
.

HTML

<div ng-repeat="(item, data) in Dc.DataToLoopThrough">
<div ng-if="item === 'flowers'">
<div ng-repeat="flowerItem in data">
<table ng-if="flowerItem.flowerType === 'Tulip'">
<tr ng-repeat="refNumber in flowerItem.flowerReferenceNumbers">
<td ng-if="refNumber.isRequiredForTracking && refNumber.value != null">
<input ng-value="refNumber.value != null ? refNumber.value : ''" type="text" />
</td>
<td ng-if="refNumber.isRequiredForTracking && refNumber.value == null">
<input ng-model="Dc.ArrayINeed[$index].refNumber" type="text" />
</td>
</tr>
</table>

最佳答案

不要同时使用 ng-valueng-model

  <table>
<tr ng-repeat="refNumber in flowerItem.flowerReferenceNumbers">
<td class="requirement-td-padding"
ng-if="refNumber.isSetForTrimming">
{{refNumber.label}}: &nbsp;
</td>
<td ng-if="refNumber.isSetForTrimming">
<input ̶n̶g̶-̶v̶a̶l̶u̶e̶=̶"̶r̶e̶f̶N̶u̶m̶b̶e̶r̶.̶v̶a̶l̶u̶e̶ ̶!̶=̶ ̶n̶u̶l̶l̶ ̶?̶ ̶r̶e̶f̶N̶u̶m̶b̶e̶r̶.̶v̶a̶l̶u̶e̶ ̶:̶ ̶'̶'̶"̶ ̶
ng-model="Dc.ArrayINeed[$index]" type="text" />
</td>
</tr>
</table>

而是在 Controller 中初始化模型:

Dc.FlowerData = function () {
var flowerArr = Dc.DataToLoopThrough.flowers;
var flowerItem = flowerArr.find(_ => _.flowerType == 'Tulip');
var refNumberArr = flowerItem.flowerReferenceNumbers;
Dc.ArrayINeed = refNumberArr.map(_ => (_.value || ''));

//....
};

关于javascript - 无法动态设置 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56133345/

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