AngularJs我有兩個數組:一個有星期,一個有佔用數。 現在起初我迭代爲期一週的陣列在一個表中:使用內聯數組迭代ng-repeat更新數組中的所有對象
<tr ng-repeat="week in weeks">
<!-- content for every week with occupancy-array -->
</tr>
在這個表我已經實現了第二NG重複的佔用陣列,每週以下結構:
Array[WeekId] = {early: null, late: null, night: null}
因此,對於3周,對象存在3次。
對象應該可以在輸入字段的每週進行操作。 所以我的HTML是:
<tr ng-repeat="week in weeks">
<td ng-repeat="(title, value) in occupancies[week.id]">
<input class="form-control" ng-model="value"/>
</td>
</tr>
但在這種情況下,我必須達到新的價值觀出了問題,因爲數組不會在範圍上改變。
於是我決定把我的第二次NG-重複改成這樣:
<td><input class="form-control" ng-model="occupancies[week.id].early"/></td>
<td><input class="form-control" ng-model="occupancies[week.id].late"/></td>
<td><input class="form-control" ng-model="occupancies[week.id].night"/></td>
現在,範圍將發生變化,但與問題,在我入住陣列中的對象進行鏡像。這意味着通過改變入住率 - 在第一週的早些時候將改變入住率 - 在其他幾周的早些時候。
我需要幫助!
你能提供[JS小提琴](https://jsfiddle.net/)嗎? – Natiq
是的,等一下。我改變了沒有$ index的工作結構。 – Phil
這是它:https://jsfiddle.net/8Lmq8ub5/ – Phil