我有一個表,我自動增加每行基於用戶的選擇。吳重複試圖創建一個計數器索引
我遇到的問題是ng-repeat複製了我無法區分它們的列。例如,列中的每個單元格使用索引編號相同。我想有一種方法來確定用戶在單元格上的點擊位置。
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th style="table-layout:fixed; text-align: center;" scope="col" colspan="2">Sales</th>
<th style="table-layout:fixed; text-align: center;" scope="col" colspan="2">Service</th>
<th style="table-layout:fixed; text-align: center;" scope="col" colspan="2">Accounting</th>
<th style="vertical-align:top; text-align: center;" scope="col" colspan="2">Parts</th>
<th style="vertical-align:top; text-align: center;" scope="col" colspan="2">Body Shop</th>
<th style="vertical-align:top; text-align: center;" scope="col" colspan="2">Other</th>
</tr>
<tr>
<th></th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
</tr>
</thead>
<tr ng-repeat="time in times">
<td>{{weekdays[$index]}}</td>
<td class="start-end-time" updated-row ng-repeat-start="(key,dept) in time" data-index="{{[key]}} start" editable-field time="dept.start"></td>
<td class="start-end-time" updated-row="{{$index}}" data-index="{{[key]}}" ng-repeat-end editable-field time="dept.end"></td>
<!-- {{times[$index][key].start}} -->
Monday Service start time {{times[0] |date: "shortTime"}}
<!-- <div id="HoursTable" newtable></div> -->
我控制器
pp.controller('main', ['$scope', '$location', function($scope, $location) {
$scope.times = [];
$scope.timeArr = [];
$scope.timeObj = {};
$scope.clickedIndex;
$scope.departments = ["sales", "service", 'accounting', 'parts', 'bodyShop', 'other'];
$scope.weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
$.each($scope.weekdays, function(index, value) {
var dayTimes = {};
$.each($scope.departments, function(index, value) {
dayTimes[value] = {
start: '',
end: ''
};
});
$scope.times.push(dayTimes);
});
}]);
我試圖創建一個數據屬性,叫做data-index="{{$index+=1}}"
希望我的例子做了一下的感覺。簡而言之,我需要給列中的每個單元格一個標識符。就像現在一樣,它們都具有相同的價值,阻止我應用任何條件邏輯。
<-- Updated -->
Located in the hours table page
ng-init="number = countInit()"
controller I added this piece of code as well:
$scope.countInit = function() {
return $scope.totalCount++;
}
當我嘗試顯示使用此語法data-index={{number}}
我的結果是空在我的表中的結果。怎麼會這樣?我幾乎覺得Angular正在對我開玩笑。或者這可能是我的無知。我寧願相信前者。
我認爲我的解決方案會工作。想知道我出錯的地方。任何謙卑的靈魂能幫助我嗎?
Stackflow社區有什麼我可以做的,以增加我獲得幫助的機會? – o6t9o