我遇到了一個奇怪的問題,我似乎無法解決我的問題。我正在使用一個生成我網站樹形視圖的指令。當我選擇一個站點時,我有兩個選擇框,其中填充了一個站點中的組和站點中的列表。當選項填充時,它們全部被選中。我檢查了元素,他們都有option="selected"
奇怪的是,當我點擊一個選項時,所有其他選項消失,只剩下選定的選項。我已經在Chrome控制檯中檢查了源代碼,只有選定的選項標記保留。ngOptions默認選擇了所有選項,並且選擇了消失選項
對於〔實施例的網站列出了選擇框有多種選擇,但是當我點擊了舊文件,但其他全部消失了。在網站用戶組,各組已經選定 Ctrl鍵:
spApp.controller('sitesCtrl',
function sitesCtrl($scope, $q, $modal, UserService, GroupService, SiteService){
//Options for tree controller directive
$scope.treeOptions = {
nodeChildren: "children",
dirSelectable: true,
injectClasses: {
ul: "a1",
li: "a2",
liSelected: "a7",
iExpanded: "a3",
iCollapsed: "a4",
iLeaf: "a5",
label: "a6",
labelSelected: "a8"
}
}
//Returns siteMap for tree controller directive
$scope.siteMap = SiteService.getSiteMap();
//Returns selected sites information: grous, lists, title, url
$scope.showSelected = function(site){
var siteData = SiteService.getSiteInfo(site);
//sets sites title and url in view
$scope.site = site;
$scope.siteGroups = siteData.groups;
$scope.siteLists = siteData.lists;
}
}
);
查看:
<div class="siteGroups">
<label for="siteGroups">Site Groups</label>
<select
multiple
name="siteGroups"
id="siteGroups"
class="siteGroups"
ng-model="siteGroups"
ng-options="g.name for g in siteGroups">
</select>
</div>
<div class="btm1 animated fadeInUp">
<label for="siteLists">Site Lists </label>
<select multiple
id="siteLists"
ng-model="siteLists"
ng-options="l.title for l in siteLists">
</select>
</div>
是的,你是對的。我改變了ngModel,它完美的工作。 – Batman