我有一个包含用户列表的表,其中每一行的最后一列都包含一个按钮。单击按钮时,会出现一个弹出表单。在弹出窗口中,我在 Angular Chosen 的帮助下使用了多项选择。每个用户都有一个“兴趣”列表,我想在多选中显示它们。问题是即使在获取了所有必要的数据之后,ng-model 似乎还是空的。
这是多选。
<select id="multipleSelect"
data-placeholder="Select interests..."
chosen
multiple
ng-model="$ctrl.activeInterests" ng-options="interest for interest in $ctrl.interests"
style="width:370px; height:100px;">
<option value=""></option>
</select>
这是我的组件。单击按钮时会触发此功能。
this.editButtonClicked = function(tableRowUser) {
$scope.firstName = tableRowUser.firstName;
$scope.lastName = tableRowUser.lastName;
$scope.email = tableRowUser.email;
$scope.role = tableRowUser.role;
$scope.tag = tableRowUser.tag;
$scope.username = tableRowUser.username;
// Fetch the active interests
fetchInterests($scope.tag);
// Fetch the available interests the user can choose
fetchAllAvailableInterests();
// After this, make the Edit Form/Popup visible
togglePopupClass();
}
function fetchInterests(newInterests) {
self.activeInterests = [];
var interests = newInterests.split('|');
console.log("New interests");
console.log(newInterests);
for (i = 0; i < interests.length; i++) {
// Trim the excess whitespace.
interests[i] = interests[i].replace(/^\s*/, "").replace(/\s*$/, "");
self.activeInterests.push(interests[i]);
}
}
调用 fetchInterests 后,“activeInterests”包含我希望 ng-model 显示的内容,但视图仍然为空。
任何帮助将不胜感激。