在负载上激活排序功能-Shuffle.js
正如标题所说,如何通过“数据标题”在负载上启动排序?我试图在HTML中活跃起来,但它不起作用。我不是JavaScript专家,但我的直觉告诉我这很容易 - 可悲的是我无法弄清楚。
https://vestride.github.io/shuffle/
emo.prototype._handleSortChange = function (evt) {
// Add and remove `active` class from buttons.
var wrapper = evt.currentTarget;
var buttons = Array.from(evt.currentTarget.children);
buttons.forEach(function (button) {
if (button.querySelector("input").value === evt.target.value) {
button.classList.add("active");
} else {
button.classList.remove("active");
}
});
// Create the sort options to give to Shuffle.
var value = evt.target.value;
var options = {};
function sortByDate(element) {
return element.getAttribute("data-title");
}
function sortByTitle(element) {
return element.getAttribute("data-title").toLowerCase();
}
if (value === "date-created") {
options = {
reverse: true,
by: sortByDate,
};
} else if (value === "title") {
options = {
by: sortByTitle,
};
}
this.shuffle.sort(options);
};
As the title says, how can I active the sort by 'data-title' on load? I tried to active it in the HTML but it didn't work. I'm no Javascript expert but my gut tells me this is easy - sadly I cant figure it out.
https://vestride.github.io/Shuffle/
emo.prototype._handleSortChange = function (evt) {
// Add and remove `active` class from buttons.
var wrapper = evt.currentTarget;
var buttons = Array.from(evt.currentTarget.children);
buttons.forEach(function (button) {
if (button.querySelector("input").value === evt.target.value) {
button.classList.add("active");
} else {
button.classList.remove("active");
}
});
// Create the sort options to give to Shuffle.
var value = evt.target.value;
var options = {};
function sortByDate(element) {
return element.getAttribute("data-title");
}
function sortByTitle(element) {
return element.getAttribute("data-title").toLowerCase();
}
if (value === "date-created") {
options = {
reverse: true,
by: sortByDate,
};
} else if (value === "title") {
options = {
by: sortByTitle,
};
}
this.shuffle.sort(options);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论