js wp.api 代码参考
Published
2023-09-10
浏览次数 : 40
包括如何用js来验证当前页面如何实现keyup状态只出发一次settimeout如何验证datatable是否加载
jQuery(document).ready(($) => {
if ($('.page-id-422').length > 0) {
console.log('this is the page-id-422');
const posts = new wp.api.collections.Posts;
posts.fetch({
data:{
per_page: 99,
context:'edit'
}
}
).done(function(res) {
const table = $("#myTable");
res.forEach((post) => {
const content = post.content.rendered;
table.append(`<tr>
<td>${post.title.rendered}</td>
<td>Row 1 Data 2</td>
<td>Row 1 Data 2</td>
<td>Row 1 Data 2</td>
<td>Row 1 Data 2</td>
<td>Row 1 Data 2</td>
<td>Row 1 Data 2</td>
<td>Row 1 Data 2</td>
</tr>`);
});
console.log(res);
});
} else {
console.log('this is not the page with this id');
}
let detimer;
$('#minprice').on('keyup',function(e) {
console.log($(this).attr('name'));
clearTimeout(detimer);
detimer = setTimeout(function(){console.log('keyup on minprice');}, 1500);
$('#size').on('change',function(e){
console.log('select changed');
});
});
if ( typeof DataTable !== "undefined") {
let table = new DataTable('#myTable', {
responsive: true
});
console.log('DataTable loaded');
}
});
- 标签1
- 标签1
- 标签1