Multiselect jQuery中json的来源 [英] source of json in Multiselect jQuery
本文介绍了Multiselect jQuery中json的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多种选择的jQuery,我想从json获取源代码. 我从有效的自动填充组合框中获取了源代码,但是在这里它不起作用.
I have a multiselect of jQuery and I want to get the source from json. I took the source code from my autocomplete combobox that works, but here it does not work.
我的代码:
$(document).ready(function () {
var warning = $("#message");
$("select").multiselect({
//selectedText: function (numChecked, numTotal, checkedItems) {
// return numChecked + ' of ' + numTotal + ' checked';
//},
source: function (request, response) {
$.getJSON('http://' + $("[id$='ip']").val() + "/JSON/Auctocomplete.aspx?city=1&term=" + request.term, function (data) { response(data); });
},
select: function (event, ui) {
$("#mfr").textContent = ui.item.id;
},
selectedList: 5,
header: "choose up to 5",
click: function (e) {
if ($(this).multiselect("widget").find("input:checked").length > 5) {
warning.addClass("error").removeClass("success").html("choose up to 5");
return false;
} else {
warning.addClass("success").removeClass("error").html("");
}
}
});
});
我搜索了
推荐答案
,我认为Jquery多重选择没有 source 属性.看看 http://www.erichynds.com/blog/jquery-ui -multiselect-widget .您确定有一个源属性吗?
I searched, and I think there is not a source property for Jquery multiselect. Take a look at http://www.erichynds.com/blog/jquery-ui-multiselect-widget . Are you sure there is a source property for it?
我建议您,首先从json中加载选择,然后将其转换为多选.
I advice you, first load select from json, then convert it to multiselect.
// The empty select element:
<select></select>
// In javascript:
$(document).ready(function () {
var url = 'http://...';
$.getJSON(url,function(result){
$.each(result, function(i, field){
var option = $('<option value="' + field.value + '">' + field.text + '</option>');
$('select').append(option);
});
$('select').multiselect({...});
});
});
这篇关于Multiselect jQuery中json的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文