使用 ng-repeat中的索引设置 ngmodel 的值



我有这个数组并使用ng-repeat迭代值。使用 ng-repeat,我将能够使用代表迭代器的$index。

在我有这个代码之前,用户输入问题订单号:

<div ng-repeat="q in entries">
  <input type="text" ng-model="q.orderNo">
</div>

但是客户要求一个可拖动的功能,以拖放要整理的问题。 例如,用户将问题 #1 拖到问题 #2 位置,然后他们的位置将更改,因此问题订单号将重新索引。有了这个,用户将不再需要输入订单号,但我仍然必须设置 q.orderNo 并在我传递给我的 api 时将$index绑定到它。

<div ng-repeat="q in entries">
  <input type="text" ng-model="q.orderNo = $index"> //this is what I want to accomplish
</div>

我想将$index分配给 q.orderNo,我该怎么做?

<input type="text" ng-model="q.orderNo" ng-init="q.orderNo = $index">

最新更新