[英]Angular js + Chosen Plugin + Set the value as Selected in dropdown
I have implement the chosen plugin in the Angular.js with the reference of this link 我已经使用此链接的引用在Angular.js中实现了所选插件
I am able to fetch the value, Now I want to the selected value as pre selected in the chosen dropdown. 我能够获取该值,现在我想将所选值作为在选定下拉列表中预先选择的值。
Can any one tell me the easy way to do this. 谁能告诉我这样做的简单方法。 Sample Code :
样例代码:
<select name="SelectedName" id="SelectedName" data-placeholder="Choose a Name..." chosen
ng-model="Info.SelectedNameModel"
ng-options="jd.Name for jd in Info.List"
class="form-control chosen-select"></select>
In Js code 用Js代码
.directive('chosen', function() {
var linker = function (scope, element, attr) {
// update the select when data is loaded
scope.$watch('Info.List', function (oldVal, newVal) {
element.trigger('chosen:updated');
});
element.chosen();
};
return {
restrict: 'A',
link: linker
};
});
Sample list : {"Name":"PQR"},{"Name":"LMN"}
样本列表:
{"Name":"PQR"},{"Name":"LMN"}
In Database I am storing the only value as 'LMN' 在数据库中,我将唯一的值存储为“ LMN”
So when the dropdown loads I want to show as LMN selected. 因此,当下拉负载加载时,我想显示为LMN。
Let me know If any one has already done this. 让我知道是否有人已经这样做。
Updated the ng-options as jd.Name for jd in Info.List track by jd
将ng-options更新为
jd.Name for jd in Info.List track by jd
You can change into this: 您可以更改为:
<select name="SelectedName" id="SelectedName" data-placeholder="Choose a Name..." chosen
ng-model="Info.SelectedNameModel"
ng-options="jd.Name for jd in Info.List track by jd"
class="form-control chosen-select"></select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.