所以我的代碼角沒有看到JSON陣列中的所有對象
$scope.pauseChecked = function(monitorId, groupName) {
for (var i = 0; i < $scope.monitorResults.length; i++) {
if (document.getElementById('checkboxId').checked) {
adminService.pauseMonitor(monitorId, groupName).then(function(response) {
$scope.getMonitorResultsForSelectedGroups();
$scope.filterResults();
var keepGoing = true;
angular.forEach($scope.monitorResults, function(monitor) {
if (keepGoing) {
if (monitor.id == monitorId && groupName == monitor.groupName) {
monitor.triggerRunning = false;
keepGoing = false;
}
}
});
});
}
}
};
這部分該行的所有的內部工作正常
<tr ng-repeat="result in monitorResults" ng-click="setSelected(result.id)" ng-class="{highlighted: result.id === selectedRow, selected: checkboxId}">
這條線外NG-重複
<td ng-show="monitorResults.triggerRunning"><button class="btn btn-info" style="width: 150px" ng-click="pauseChecked(monitorResults.id, monitorResults.groupName)">Pause Checked </button></td>
並且這是怎麼看它的頁面
<table style="float:left; margin-left: auto; margin-right: auto;">
<tr >
<td><button class="btn btn-primary" ng-click="runAllMonitorsNew()" style="width: 150px">Run All Monitors</button></td>
<td ng-show="!checkedGroup"><button class="btn btn-primary" style="width: 150px" ng-click="pauseGrMonitors(result.groupName)">Pause Monitors</button></td>
<td ng-show="checkedGroup"><button class="btn btn-primary" style="width: 150px" ng-click="resumeGrMonitors(result.groupName)">Resume Monitors</button></td>
</tr>
<tr>
<td><button ng-click="runChecked(result.id,result.groupName)" class="btn btn-info" style="width: 150px">Run Checked</button></td>
<td ng-show="monitorResults[0].triggerRunning"><button class="btn btn-info" style="width: 150px" ng-click="pauseChecked(monitorResults.id,monitorResults.groupName)">Pause Checked </button></td>
<td ng-show="!monitorResults[0].triggerRunning"><button class="btn btn-info" style="width: 150px" ng-click="resumeChecked(monitorResults.id,monitorResults.groupName)">Resume Checked</button></td>
</tr>
</table>
<table style="float: right; margin-right: 50px">
<tr>
<td>
<json-editor-input model="monitorResults" configuration="configuration" on-error="onError(err)"/>
</td>
</tr>
</table>
</div>
<BR>
<img class="center-block" src="ajax-loader.gif" ng-show="loading"/>
<BR>
<table class="table table-striped table-bordered">
<tr>
<td><B>Monitor Id</B></td>
<td><B>Monitor Name</B></td>
<td><B>Monitor Type</B></td>
<td><B>Group Type</B></td>
<td><B>Warn Threshold</B></td>
<td><B>Error Threshold</B></td>
<td><B>Monitor Result</B></td>
<td><B>Compare Result</B></td>
<td><B>Last Run Date</B></td>
</tr>
<tr ng-repeat="result in monitorResults" ng-click="setSelected(result.id)" ng-class="{highlighted: result.id === selectedRow, selected: checkboxId}">
<td><input type="checkbox" ng-model="checkboxId" id="checkboxId" name="checkboxId"></td>
<td>{{result.id}}</td>
<td>{{result.name}}</td>
<td>{{result.type}}</td>
<td>{{result.groupName}}</td>
<td>{{result.warnThreshold}}</td>
<td>{{result.errorThreshold}}</td>
<td>{{result.monitorResult}}</td>
<td> <p ng-style="changeColor(result.compareResult)">{{result.compareResult}}</p> </td>
<td>{{result.lastRunTime}}</td>
<td> <button class="btn btn-primary" ng-click="runMonitorNew(result.id,result.groupName)">Run</button> </td>
<td ng-show="result.triggerRunning"><button class="btn btn-primary" ng-click="pause(result.id,result.groupName)">Pause</button> </td>
<td ng-show="!result.triggerRunning"><button class="btn btn-primary" ng-click="resume(result.id,result.groupName)">Resume</button> </td>
</tr>
這是我在調試器
你能看的見,我已經取代了「結果」的「monitorResults」,因爲它給了我訪問數組,但事情是當我通過調試器檢查代碼時,我發現monitorId和groupname是未定義的。因此,我已經使用monitorResults [0] .id和monitorResults [0] .groupName,但它給了我只訪問數組中的第一個元素,如何獲得每個元素的訪問?
你爲什麼換成''monitorResults' result'? 'result.groupName'和'result.id'應該給你想要的結果 – nikhil
你能在塊中顯示更多的html視圖嗎?我想看看td元素在tr之外的意思。 –
ok,lemme 3分鐘 – Anton