2016-04-27 38 views
0

NG-模型的值是簡單的數字數組:[8]使用UI-JQ預選上下拉選項不作品

HTML代碼

    <select ui-jq="chosen" multiple="true" class="w-md" name="careers" id="careers" ng-model="loan_plan.careers" ng-options="opt.id as opt.id for opt in careersOptions" > 
        </select> 

並且選項是對象數組

[ 
{ 
id: 10, 
name: "statistician", 
description: "Food truck artisan 3 wolf moon tilde. Franzen aesthetic you probably haven't heard of them ennui tumblr. Fingerstache distillery ugh. Meggings you probably haven't heard of them lomo. Mixtape jean shorts pbr&b twee chillwave authentic trust fund." 
}, 
{ 
id: 9, 
name: "engineer", 
description: "Wes anderson polaroid jean shorts meggings etsy roof listicle 90's. Tote bag plaid green juice. Microdosing 8-bit austin migas." 
}, 
{ 
id: 8, 
name: "police officer123434", 
description: "Tattooed vinyl jean shorts irony. Iphone wolf kinfolk austin venmo semiotics authentic slow-carb. Farm-to-table poutine letterpress asymmetrical hammock microdosing. 3 wolf moon viral offal portland." 
} 
] 

正如你可以看到8號已經加載頁面

前已經存在,但它並沒有作爲s當選文本字段

inline

inline

回答

0

嘗試。你應該用對象來初始化模型。

var app = angular.module("testApp", []); 
 
app.controller('testCtrl', function($scope){ 
 
    $scope.loan_plan ={careers:[]}; 
 
    $scope.careersOptions = [ 
 
{ 
 
id: 10, 
 
name: "statistician", 
 
description: "Food truck artisan 3 wolf moon tilde. Franzen aesthetic you probably haven't heard of them ennui tumblr. Fingerstache distillery ugh. Meggings you probably haven't heard of them lomo. Mixtape jean shorts pbr&b twee chillwave authentic trust fund." 
 
}, 
 
{ 
 
id: 9, 
 
name: "engineer", 
 
description: "Wes anderson polaroid jean shorts meggings etsy roof listicle 90's. Tote bag plaid green juice. Microdosing 8-bit austin migas." 
 
}, 
 
{ 
 
id: 8, 
 
name: "police officer123434", 
 
description: "Tattooed vinyl jean shorts irony. Iphone wolf kinfolk austin venmo semiotics authentic slow-carb. Farm-to-table poutine letterpress asymmetrical hammock microdosing. 3 wolf moon viral offal portland." 
 
} 
 
]; 
 
    
 
    $scope.loan_plan.careers= $scope.careersOptions[2]; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="testApp" ng-controller="testCtrl"> 
 

 
     <select ui-jq="chosen" multiple class="w-md" name="careers" id="careers" ng-model="loan_plan.careers" ng-options="opt.id as opt.id for opt in careersOptions" > 
 
        </select> 
 
</div>

+0

喜也沒有工作,請看到我的更新〜 – newBike