javascript - 致敬.js中这个回调参数是什么意思?
问题描述
js新手。我正在开发一个个人网站,该网站使用贡品.js 具有@mention 功能。就我而言,我需要从远程服务器检索提及列表。官方文档给出了一个实现的例子。令我困惑的是cb
参数的含义,它甚至没有在任何地方定义。谁能帮忙解释一下?
{
//..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();
}
解决方案
含义隐藏在您的问题的标题中,cb
意味着回调:)
它被函数调用,而该remoteSearch
函数又被调用了cb
由贡品.js引擎传递的参数。
推荐阅读
- excel - 删除行直到定义列的宏代码
- c# - 将对象列表转换为类型数组并删除空值
- python - 如何将每个数组数据保存到数据库?一个数据作为一行
- python - 在将数据传递到循环神经网络之前缩放数据(MinMaxScaler 和 StandardScaler)及其对输出的影响
- python - Seaborn 头衔位置
- android - I/chromium: [INFO:CONSOLE(1)] 在 Web 视图中调用时出现“ERROR”角度 5 错误
- apache-spark - 将文件中的参数传递给多个 Spark 作业
- php - PHPWord读取保留样式的word文档
- react-native - React Native - 键盘有条件地推动内容渲染器
- python - 两个 Spark 数据帧的联合