Javascript Typeahead:为什么在事件$Typeahead.select之后将请求发送到服务器?
提前键入以所选值向服务器发送请求。 我觉得没有必要,怎么预防呢Javascript Typeahead:为什么在事件$Typeahead.select之后将请求发送到服务器?,javascript,angularjs,typeahead.js,angular-strap,Javascript,Angularjs,Typeahead.js,Angular Strap,提前键入以所选值向服务器发送请求。 我觉得没有必要,怎么预防呢 例如,使用typeahead-minlength和typeahead-wait-ms <input typeahead-min-length="3" typeahead-wait-ms="1000" .... 在输入至少3个字符并且暂停1000毫秒之前,不会对函数进行调用。也就是说,用户停止输入那么长时间。当你希望帮助最小化所拨打的电话号码时,播放这些值。你能考虑改写吗?你到底想阻止什么?对服务器不必要的调用?
例如,使用typeahead-minlength和typeahead-wait-ms
<input typeahead-min-length="3" typeahead-wait-ms="1000" ....
在输入至少3个字符并且暂停1000毫秒之前,不会对函数进行调用。也就是说,用户停止输入那么长时间。当你希望帮助最小化所拨打的电话号码时,播放这些值。你能考虑改写吗?你到底想阻止什么?对服务器不必要的调用?
$scope.getAddress = function(viewValue) {
var params = {address: viewValue, sensor: false};
return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {params: params})
.then(function(res) {
angular.forEach(res.data.results, function(o) {
o.label = o.formatted_address;
});
console.log(res.data.results)
return res.data.results;
});
};
<input typeahead-min-length="3" typeahead-wait-ms="1000" ....