我已经像这样嵌套了ng-repeat:
<div ng-repeat="(dayOfWeek, time) in uiHoursOfOperation track by $index" ng-init="daysOfWeekIndex=$index">
<div class="" ng-repeat="openCloseSet in time.uiDayMs track by $index">
<md-input-container>
<md-select ng-model="openCloseSet[0]" ng-init="openTime = openCloseSet[0]">
<md-option ng-repeat="uiTime in time.avaiableTime" ng-value="uiTime.msValue">
{{::uiTime.display}}
</md-option>
</md-select>
</md-input-container>
<md-input-container ng-if="$index === 0">
<md-button ng-click="addSplitHours(time.uiDayMs ,$index +1, time)">
Add
</md-button>
</md-input-container>
</div>
</div>
点击添加按钮。它会创建一个time.uiDayMs
的新块。
这是添加功能:
$scope.addSplitHours = addSplitHours;
function addSplitHours(index, time) {
var newOpen = time.uiDayMs[time.uiDayMs.length - 1][1] + 900000;
time.uiDayMs.push([newOpen, newOpen + 900000 * 4]);
var closingtimeStarts = closingTime + 900000;
var closingtimeEnds = avaiableClosingTimes[avaiableClosingTimes.length - 1].msValue;
for (
var msValue = closingtimeStarts;
msValue <= closingtimeEnds;
msValue += 900000
) {
time.avaiableTime.push({
msValue: msValue,
display: moment(msValue)
.utc()
.format("h:mm A")
});
}
}
您可以看到我使用下一个索引编号但无法使用它
所以我的主要问题是如何才能使time.avaiableTime.push
只针对那个特定的索引?目前,它在每个time.avaiableTime
上都会发生变化,但我只想推广该特定索引。