正文  软件开发 > html5 >

Knockoutjs+select2 人员搜索,knockoutjsselect2

Knockoutjs+select2 人员搜索,knockoutjsselect2 HTML: <select class="form-control PersonEmail" id="txt...

Knockoutjs+select2 人员搜索,knockoutjsselect2

HTML:

<select class="form-control PersonEmail" id="txtProjectManager" data-bind="options:{text:ICVInfo.ProjectManager,value:ICVInfo.ProjectManager},optionsText:‘text‘,optionsValue:‘value‘,value:ICVInfo.ProjectManager" ></select>

javascript:

$(‘.PersonEmail‘).select2({
"separator": ",",
"maximumSelectionSize": 10,
"placeholder": "请选择用户",
"allowClear": false,
"maximumInputLength": 100,
"minimumResultsForSearch": "2",
"tags": false,
templateResult: function (repo) {
markup = repo.text;
return markup;
},
escapeMarkup: function (markup) { return markup; },
templateSelection: function (repo) {
return repo.text;
},

ajax: {
@*url: ‘@Url.Action("SelectUser", "CommercialReminder")‘, dataType: ‘json‘, data: function (params) {*@
url: ‘SelectUser‘,
dataType: ‘json‘,
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
params.page = params.page || 1;

return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: false,
type: ‘post‘
},
initSelection: function (element, callback) {
if (element.val() != null) {
var data = { id: element.val(), text: element.val() };
//alert(data.id);
callback(data); //这里初始化
}
}
})

目前只适合单选,多选目前还在配置,等测试通过后会继续放上来。

http://www.bkjia.com/HTML5/1218425.htmlwww.bkjia.comtruehttp://www.bkjia.com/HTML5/1218425.htmlTechArticleKnockoutjs+select2 人员搜索,knockoutjsselect2 HTML: select class="form-control PersonEmail" id="txtProjectManager" data-bind="options:{text:ICVInfo.ProjectManager,value:ICV...