image我有一个api,当我单击mehr(more)按钮时,该api从Jasonfile加载了10个项目。如果再次单击,它将再加载10个,依此类推...在JPlayer documentation中,它们仅显示如何一次删除1个项目:
myPlaylist.remove(); // Removes all items
myPlaylist.remove(0); // Removes the 1st item
myPlaylist.remove(1); // Removes the 2nd item
myPlaylist.remove(-1); // Removes the last item
当我单击weniger(less)按钮时是否可以一次删除10个项目?我尝试过:
$(".pc-less-btn.btn-{{ pk }}").click(function() {
myPlaylist.remove(10); // To Removes 10 items but doesn't works
});
答案 0 :(得分:1)
选项1:设置新的播放列表
$(".pc-less-btn.btn-{{ pk }}").click(function() {
const removeFromIndex = 10
// remove from end
const newPlaylist = myPlaylist.playlist.slice(myPlaylist.playlist.length - removeFromIndex)
// remove from start
// const newPlaylist = myPlaylist.playlist.slice(removeFromIndex)
myPlaylist.setPlaylist(newPlaylist)
});
选项2:一一删除(不推荐)
$(".pc-less-btn.btn-{{ pk }}").click(function() {
for (let i = 0; i < 10; i++) {
myPlaylist.remove(i); // indexes of playlist probably changes
}
});
答案 1 :(得分:0)
这是一个棘手的解决方案。我想从播放列表中删除所有项目,所以我正在寻找解决方案,所以我发现这个技巧到目前为止对我有用。我已经在 2.9.2 版本中测试过
假设您的播放列表对象是 player
,因此在任何 jQuery 单击事件中,您都可以像这样获取所选列表索引
$("#selector_id").on("click", function (e) {
var object = $(this);
var ids = []; // Fetch you ids in your way, either checkbox or anything or manual enter
// Then get the playlist from the player object.
var playlist = player.playlist;
// Check if playlist has data.
if (playlist && playlist.length) {
var new_playlist = [];
$.each(playlist, function (index, item) {
// If index is not in your ids then get the playlist item.
if (!ids.includes(index)) {
new_playlist.push(item);
}
});
// Now you have new playlist after removing selected items.
// Check if we have anything in new playlist.
if (new_playlist.length) {
// If we have data in new playlist then init playlist.
player._initPlaylist(new_playlist);
// Then call the refresh function with clearMedia event.
player._refresh(function () {
$(player.cssSelector.jPlayer).jPlayer("clearMedia");
});
// You can call update Control if you have Controls enabled.
}
}
});