我在设置电路板时尝试这样做,列表应该更新,如果它是空的,如果它没有在列表中显示数字0
,它将显示n / a。但是当我设置一个有4个列表的电路板时,我遇到了一个问题。然后我将列表设置为最后一个位置,例如4
,然后我将设置一个没有列表的数组。我没有设置默认的n / a,只在drop-down list
中。
我试过设置$scope.selectedList = '0'
;并且它适用于更换有列表而不是它们不在的地方的电路板。
请帮助。 这是代码:
控制器中的模板
$scope.changeBoard = (_id) => {
var params = {
_id: _id
};
return ApiService.staff.selectedBoard(params).then((resp) => {
if (resp.lists.length === 0 || !resp.lists) {
$scope.downloadedLists.lists = [];
$scope.selectedList = '0';
} else {
$scope.downloadedLists = resp;
if (_id === $scope.board._id) {
$scope.selectedList = $scope.mainList;
$scope.selectedCard = $scope.mainCard;
} else {
$scope.selectedList = '0';
$scope.selectedCard = '0';
}
}
});
};
模板html
<div class="transfer-btn">
<span>Tablica</span>
<span>{{board.name}}</span>
<select class="form-control" ng-model="selectedBoard" ng-change="changeBoard(selectedBoard)">
<option ng-repeat="item in boards" value="{{item._id}}">
{{item.name}}
</option>
</select>
</div>
<div class="transfer-btn">
<span>Lista{{selectedList}}</span>
<span>{{board.name}}</span> {{selectedListIn}}
<select class="form-control" name="" id="" ng-model="selectedList" ng-change="">
<option ng-repeat="item in downloadedLists.lists" value="{{$index}}">
{{item.list}}
</option>
<option value="0" ng-show="downloadedLists.lists.length == 0">n/a</option>
</select>
</div>
答案 0 :(得分:0)
你有一些测试数据吗?
如果您将拥有如下示例的测试数据,那么您应该测试和调试。以下示例将测试数据设计为从0到4的5个大小。之后,您应该逐个试用并查看结果。
然后,它将为您提供下一步测试和调试的线索。
Test Data 0:
var boardDataTest0 = [];
Test Data 1:
var boardDataTest1 = [
{"id":1, "name": "board1", "description": "bla..bla..bla1" }
];
Test Data 2:
var boardDataTest2 = [
{"id":1, "name": "board1", "description": "bla..bla..bla1" },
{"id":2, "name": "board2", "description": "bla..bla..bla2" }
];
Test Data 3:
var boardDataTest3 = [
{"id":1, "name": "board1", "description": "bla..bla..bla1" },
{"id":2, "name": "board2", "description": "bla..bla..bla2" },
{"id":3, "name": "board3", "description": "bla..bla..bla3" }
];
Test Data 4:
var boardDataTest4 = [
{"id":1, "name": "board1", "description": "bla..bla..bla1" },
{"id":2, "name": "board2", "description": "bla..bla..bla2" },
{"id":3, "name": "board3", "description": "bla..bla..bla3" },
{"id":4, "name": "board4", "description": "bla..bla..bla4" }
];