1 回答
TA贡献1725条经验 获得超7个赞
在插件jquery.placecomplete.js代码中发现了问题。将默认id参数替换为 use place_id,因为id谷歌自动完成已弃用。
我补充说:apr["id"] = apr["place_id"];在现有代码之上:apr["text"] = apr["description"];
这是添加的整个代码块:
var select2options = $.extend({}, {
query: function(query) {
GooglePlacesAPI.getPredictions(query.term, requestParams)
.done(function(aprs) {
var results = $.map(aprs, function(apr) {
// Select2 needs a "text" and "id" property set
// for each autocomplete list item. "id" is
// already defined on the apr object
apr["id"] = apr["place_id"];
apr["text"] = apr["description"];
return apr;
});
query.callback({results: results});
})
.fail(function(errorMsg) {
$el.trigger(pluginName + ":error", errorMsg);
query.callback({results: []});
});
},
initSelection: function(element, callback) {
// initSelection() was triggered by value being defined directly
// in the input element HTML
var initText = $el.val();
// The id doesn't matter here since we're just trying to prefill
// the input with text for the user to see.
callback({id: 0, text: initText});
},
minimumInputLength: 1,
selectOnBlur: true,
allowClear: true,
multiple: false,
dropdownCssClass: "jquery-placecomplete-google-attribution",
placeholder: this.options.placeholderText
}, this.options);
添加回答
举报