我使用了以下代码:
<div class="col-lg-3">
<select ng-model="userportal.data.owner_id" class="form-control uniformselect" id="owner_id" style="border-radius: 4px;">
<option value="" id=""> Select Device </option>
<option ng-repeat="device in deviceStatus" value="{{device.device_id}}">
<span ng-repeat="user in userFilter">
<span ng-if="{{user.id}} == {{device.device_id}}">
{{user.name}} {{device.device_id}}
<span/>
</span>
</option>
</select>
</div>
我得到{{device.device_id}}
的值但是,我没有得到{{user.id}}
和{{user.name}}
的值。任何人都可以帮我解决这个问题。我怎样才能在这里得到这些值。
答案 0 :(得分:1)
试试这段代码
<强> Working Demo 强>
<强>脚本强>
var myApp = angular.module('myApp', []);
myApp.controller('Controller', function ($scope) {
$scope.userFilter = [{
id: 1,
name: 'ABC'
}, {
id: 2,
name: 'LMN'
}, {
id: 3,
name: 'OPQ'
}, {
id: 4,
name: 'RST'
}, {
id: 5,
name: 'UVW'
}];
$scope.deviceStatus = [{
device_id: 1
}, {
device_id: 4
}, {
device_id: 5
}];
$scope.result = [];
angular.forEach($scope.deviceStatus, function (deviceObj) {
angular.forEach($scope.userFilter, function (userObj) {
if (deviceObj.device_id == userObj.id) {
var newObj = {};
newObj.id = userObj.id;
newObj.name = userObj.name;
$scope.result.push(newObj);
}
});
});
});
<强> HTML 强>
<div ng-app="myApp" ng-controller="Controller">
<div class="col-lg-3">
<select ng-model="userportal.data.owner_id" class="form-control uniformselect" id="owner_id" style="border-radius: 4px;">
<option value="" id="">Select Device</option>
<option ng-repeat="users in result" value="{{users.id}}">{{users.name}} {{users.id}}</option>
</select>
</div>
</div>