如何在表加载后更改占位符文本?没有jQuery。
理想步骤:
- 表加载。没有数据。占位符显示:"正在获取数据">
- JSONdata是通过以下方式获取的:
// Script
const getJSON = async url => {
try {
const response = await fetch(url);
if(!response.ok)
throw new Error(response.statusText);
const data = await response.json();
return data;
} catch(error) {
return error;
}
};
// HTML
var table = new Tabulator("#example", {
ajaxLoader: false,
data:JSONdata,
...
...
}
getJSON('https://...').then(JSONdata => {
table.replaceData(JSONdata);
}).catch(error => {
console.error(error);
});
- 占位符文本更改为:"No results found.">
注:当JSON失败或找不到搜索结果时,此特性非常重要。我添加了一个搜索函数,只显示匹配的行。
table.options.placeholder.firstElementChild.textContent = 'No results found.';
可能应该在getJSON.then()
块。