New to js. I am developing a personal site which uses tribute.js to have an @mention feature. In my case, I need to retrieve the mention list from a remote server. The official document gives an example to implement it. The thing confusing me is the meaning of cb
parameter which is not even defined in anywhere. Could anyone help to explain it?
{
//..other config options
// function retrieving an array of objects
values: function (text, cb) {
remoteSearch(text, users => cb(users));
},
lookup: 'name',
fillAttr: 'name'
}
// ajax
function remoteSearch(text, cb) {
var URL = "YOUR DATA ENDPOINT";
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
cb(data);
} else if (xhr.status === 403) {
cb([]);
}
}
};
xhr.open("GET", URL + "?q=" + text, true);
xhr.send();
}
Meaning is hiding in the title of your question, cb
means callback :)
It gets called by the remoteSearch
function which in its turn was called with cb
parameter passed by the tribute.js engine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.