我有一个指令,它接受一个集合并构建一个下拉列表。
.directive("lookupdropdown", function () {
return {
restrict: 'E',
scope: {
collectionset: '=',
collectionchoice: '='
},
replace: true,
template: '<select class="input-large" ui-select2 ng-model="collectionchoice" data-placeholder="">' +
' <option ng-repeat="collection in repeatedCollection" value="{{collection.id}}">{{collection.description}}</option>' +
'</select>',
controller: ["$scope", function ($scope) {
$scope.repeatedCollection = new Array(); //declare our ng-repeat for the template
$scope.$watch('collectionset', function () {
if ($scope.collectionset.length > 0) {
angular.forEach($scope.collectionset, function (value, key) { //need to 'copy' these objects to our repeated collection array so we can template it out
$scope.repeatedCollection.push({ id: value[Object.keys(value)[0]], description: value[Object.keys(value)[1]] });
});
}
});
$scope.$watch('collectionchoice', function (newValue, oldValue) {
debugger;
$scope.collectionchoice;
});
} ]
}
});
这工作正常。它建立了下拉没有问题。当我更改下拉值时,第二个监视函数被调用,我可以看到它将集合选择的值设置为我想要的值。但是,我放入指令中的 collectionchoice 并没有绑定到新的选择。
<lookupDropdown collectionset="SecurityLevels" collectionchoice="AddedSecurityLevel"></lookupDropdown>
那就是 HTML 标记。
这是javascript:
$scope.SecurityLevels = new Array();
$scope.GetSecurityLevelData = function () {
genericResource.setupResource('/SecurityLevel/:action/:id', { action: "@action", id: "@id" });
genericResource.getResourecsList({ action: "GetAllSecurityLevels" }).then(function (data) {
$scope.AddedSecurityLevel = data[0].SCRTY_LVL_CD;
$scope.SecurityLevels = data;
//have to get security levels first, then we can manipulate the rest of the page
genericResource.setupResource('/UserRole/:action/:id', { action: "@action", id: "@id" });
$scope.GetUserRoles(1, "");
});
}
$scope.GetSecurityLevelData();
然后,当我发布我的新用户角色时,我将用户角色字段设置为:
NewUserRole.SCRTY_LVL_CD = $scope.AddedSecurityLevel;
但这仍然是第一项,即使我已经更新了下拉列表,根据手表功能,它已更改为正确的值。我在这里想念什么?