您好我正在使用select2远程获取数据,然后用户可以输入搜索字符串并返回匹配的数据
到目前为止,我在我的选择2
中进行了ajax调用ajax: {
url: "data/more.json",
dataType: 'json',
quietMillis: 100,
data: function (term, page) { // page is the one-based page number tracked by Select2
return {
q: term, //search term
page_limit: 10, // page size
page: page // page number
};
},
results: function (data, page) {
var more = (page * 10) < data.total;
console.log(more);
console.log(data.data.moreList);
// notice we return the value of more so Select2 knows if more results can be loaded
return {results: data.data.moreList, more: more};
}
}
这里是json文件
{"data": {
"moreList": [{
"id": "1",
"label": "Type",
"jsonFile": "type.json"
},{
"id": "2",
"label": "Primary Applicant Name",
"jsonFile": "primary.json"
},{
"id": "3",
"label": "Address",
"jsonFile": "address.json"
},{
"id": "4",
"label": "Product",
"jsonFile": "product.json"
},{
"id": "5",
"label": "Verification",
"jsonFile": "verification.json"
},{
"id": "6",
"label": "Documents",
"jsonFile": "documents.json"
},{
"id": "7",
"label": "Suburb",
"jsonFile": "suburb.json"
},{
"id": "8",
"label": "State",
"jsonFile": "state.json"
}]
}
}
当我现在搜索它返回json中的所有结果而不仅仅是输入的结果时 - 我真的只是希望它显示输入的内容,如果有任何结果
如果有更好的方法,愿意采取另一种方式
显然,通过q是腐烂的西红柿有没有推出json设置api的方式我需要设置api调用最终进行服务器调用并传递这些变量,但是想知道我是否可以在原型设计时搜索JSON文件
干杯