我希望在我的模态中选择一个取决于 $ http 结果。
这是我的模板模式
var templateModal = "<div class='modal-body'>" +
"<span>Orderer List </span>" +
"<select ng-model='editable.orderer' ng-init='editable.orderer=\"{{editable.orderer_id}}\"'>" +
"<option ng-repeat='x in ordererNames' value='{{x.ID}}'>{{x.post_title}}</option>" +
"</select> <br/>" +
"</div>";
这是我打开模态的脚本
$scope.edit = function(data) {
var modalInstance = $uibModal.open({
template:templateModal,
controller: managementModal,
resolve: {
items: function() {
return data;
}
}
});
}
管理模式控制器
var managementModal = function($scope, $http, $uibModalInstance, items){
$scope.names = items;
$scope.editable = items;
$http({
method: "POST",
url: Ajax_call.ajaxurl,
params: {
action: "orderer_names"
}
}).then(function(names){
$scope.ordererNames = names.data;
console.log($scope.ordererNames[0].ID)
});
$http({
method: "POST",
url: Ajax_call.ajaxurl,
params: {
action: "creator_names"
}
}).then(function(names){
$scope.creatorNames = names.data;
});
$scope.cancel = function(){
$uibModalInstance.dismiss(true);
};
$scope.update = function(){
$uibModalInstance.close($scope.editable);
};
};
这是我到目前为止尝试过的,如果我把它放在一个ng-init它没有被选中但是当我将{{editable.orderer_id}}
更改为数字时它会被选中。我不知道为什么?
"<select ng-model='editable.orderer' ng-init='editable.orderer=\"{{editable.orderer_id}}\"'>" +
我也尝试了 ng-selected
"<option ng-selected='editable.orderer_id == x.ID' ng-repeat='x in ordererNames' value='{{x.ID}}'>{{x.post_title}}</option>"
但仍然没有运气
已经阅读了这个答案
EDITED
JSON
[{
"ID": 403,
"post_title": "Kelly Johnson"
}, {
"ID": 337,
"post_title": "Staff"
}, {
"ID": 287,
"post_title": "Marie Cury"
}, {
"ID": 278,
"post_title": "Matugas"
},{
"ID": 102,
"post_title": "Antony Edison"
}]