请检查plunker。我无法像这样绑定(bind)来自服务器的数据(["Monday","Tuesday"])
。
我知道数据是绑定(bind)的
$scope.selectedUser = [{ id: 2, name: 'Monday' },
{id: 3,name:'Tuesday'}];.
我想将 ["Monday","Tuesday"]
设为 [{ id: 2, name: 'Monday' },{id: 3,name:'Tuesday' }]
在 javascript 中,以便它可以在下拉列表中绑定(bind)。
请帮我解决这个问题。
最佳答案
//This is the ng filter to create id as you get the data from server
app.filter('createId',function(){
return function(arr){
var result = [];
for(var i = 0;i < arr.length;i++){
var id = arr[i].substring(0,3);
var obj = {'id':id,'name':arr[i]};
result.push(obj);
}
return result;
}
});
//In js controller you can costomize your array of user by using ng-filter like this
$scope.users = $filter('createId')($scope.users);
//This is because index will be changed every time so this can't be used as ID
$scope.selectedUser = $filter('createId')($scope.selectedUser);
关于javascript - 无法将数据绑定(bind)到angularjs中的下拉多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38259758/