You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
725 B
36 lines
725 B
import jsonp from 'jsonp';
|
|
import querystring from 'querystring';
|
|
let timeout;
|
|
let currentValue;
|
|
|
|
export function fetch(value, callback) {
|
|
if (timeout) {
|
|
clearTimeout(timeout);
|
|
timeout = null;
|
|
}
|
|
currentValue = value;
|
|
|
|
function fake() {
|
|
const str = querystring.encode({
|
|
code: 'utf-8',
|
|
q: value,
|
|
});
|
|
/*eslint-disable */
|
|
jsonp(`http://suggest.taobao.com/sug?${str}`, (err, d) => {
|
|
if (currentValue === value) {
|
|
const result = d.result;
|
|
const data = [];
|
|
result.forEach(r => {
|
|
data.push({
|
|
value: r[0],
|
|
text: r[0],
|
|
});
|
|
});
|
|
callback(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
timeout = setTimeout(fake, 300);
|
|
}
|