【发布时间】:2015-01-17 16:25:22
【问题描述】:
大家好,我很难弄清楚我应该如何将一个比默认值更多的对象传递给 onSelect 以获得更广泛的使用。这是我的代码,任何帮助将不胜感激!
$("input[type='text']").typeahead({
onSelect: function(item) {
// Do things with the item object here.
},
items: 10,
ajax: {
url: "modules/scripts/Search.php",
timeout: 500,
triggerLength: 1,
method: "POST",
preDispatch: function (str) {
return {
String: str,
State: $("#"+$("#"+InputBox).attr("data-place")+"StateText").attr("data-sc")
}
},
preProcess: function (data) {
if (data.success === false) { return false; }
// I think I'd create the item object here, or pass it along?
var DD = [];
$.each(data, function(key, value) {
DD.push(value['City']+" - "+value['Zip']);
TempArr[value['ID']] = data[key];
});
return DD;
}
}
});
【问题讨论】:
标签: php jquery ajax twitter-bootstrap bootstrap-typeahead