我的数据看起来像每个条目log
,来自SupportService
var getDummyLogsForNow = function () {
return [
{
"fileName": "file A",
"location": "logs/fileA",
"size": "20000",
"lastUpdated": "May 04, 2015 09:21PM"
},
{
"fileName": "file B",
"location": "logs/fileB",
"size": "4034300",
"lastUpdated": "May 01, 2015 01:21PM"
},
{
"fileName": "file C",
"location": "logs/fileC",
"size": "53437000",
"lastUpdated": "May 02, 2015 03:11PM"
}
]
};
return {
logs: getDummyLogsForNow()
};
在我的控制器中,我将其用作
$scope.logs = SupportService.logs;
$scope.selectedLogs = ["file C"];
这就是我在HTML表格上打印它们的方式
<table class="logsTable">
<thead>
<tr>
<th>#</th>
<th>File Name</th>
<th>Last Updated</th>
<th>Size</th>
<th>Location</th>
</tr>
</thead>
<tr ng-repeat="log in logs">
<td>
<input type="checkbox"
ng-checked="selectedLogs.indexOf(log.fileName) != -1"
ng-click="toggleSelect(log)">
</td>
<td>{{log.fileName}}</td>
<td>{{log.lastUpdated}}</td>
<td>{{log.size}}</td>
<!--<td>{{log.location}}</td>-->
<td>{{selectedLogs.indexOf(log.fileName) != -1}}</td>
</tr>
</table>
即使其中一个条目true
,也未检查checkbox
。我所看到的只是
这里的问题是什么?
答案 0 :(得分:0)
我认为你引用你的模型可能有问题。我简化了您的示例(删除了服务),并在此处提供了一个有效的示例:https://jsfiddle.net/fpnte4td/6/
所以可能控制器或服务中必定存在某些内容......您是否可以尝试直接在控制器中定义样本数据,如下所示?
$scope.logs = [{
"fileName": "file A",
"location": "logs/fileA",
"size": "20000",
"lastUpdated": "May 04, 2015 09:21PM"
},{
"fileName": "file B",
"location": "logs/fileB",
"size": "4034300",
"lastUpdated": "May 01, 2015 01:21PM"
},{
"fileName": "file C",
"location": "logs/fileC",
"size": "53437000",
"lastUpdated": "May 02, 2015 03:11PM"
}
];
如果这没有用,请发布服务和控制器的全部内容(跳过不相关的部分)