请帮忙......
我需要显示一个特定的索引,该索引已经被数据库采用并通过ng-repeat在html视图中显示,并且在检查了特定索引后使用checklist-model我将在下面显示文本框以插入文本到把它再次放回数据库中。
这是我的代码和JSON对象,它有多个DB占用的对象:
mainApp.controller('illnessFollowController', ['$scope','$http', function ($scope, $http) {
console.log('illnessFollowController controller initialized')
$http({
method : "GET",
url : "resource/getIllnessList",
headers : {
'Content-Type' : 'application/json'
}
}).then(function Success(response) {
$scope.illnesList = response.data;
}, function Error(response) {
console.log("this is a get Error");
$scope.error;
});
$scope.user = {
appliedIlnessIDs: []
}
}]);
illnesList数组有:
[
{id:1;
name:"illness 1";
Active:1;}
{id:2;
name:"illness 2";
Active:1;}
{id:3;
name:"illness 3";
Active:1;}
]
这些值我想直接在视图中显示它们
HTML代码:
<div ng-controller="illnessFollowController" dir="rtl">
<label ng-repeat="illness in illnesList">
{{illness.name}} <input type="checkbox" checklist-model="user.appliedIlnessIDs" checklist-value="illness.id">
<br />
</label>
<div ng-show="">
</div>
</div>
我希望一旦我检查了ID 3,就会出现ng-show
答案 0 :(得分:2)
您可以使用以下内容:
<div ng-show="user.appliedIlnessIDs.indexOf(3) !== -1">
<p>This content will show if ID 3 is in user.appliedIlnessIDs array</p>
</div>
答案 1 :(得分:0)
我更改了代码,这个代码运行良好......
<span ng-repeat="illness in illnesList">
<label for="{{illness.id}}">
{{illness.name}} <input type="checkbox" ng-model="selection.id[illness.id]" id="{{illness.id}}" />
</label>
</span>
<div ng-show="selection.id[3]"><input type="text" ng-model="other"></div>
和javascript方面我添加了这个:
$scope.selection = {};
$scope.other ="";
感谢您 SO MUCH 的帮助