gpt4 book ai didi

jquery - 如何使用带有 knockout 功能的 Jquery Table Sorter

转载 作者:行者123 更新时间:2023-12-03 22:37:30 25 4
gpt4 key购买 nike

我有一个需要应用排序的表。我正在使用 knockout 和 jquery.tablesorter.js。我也尝试过自定义绑定(bind),但没有帮助。如果没有 knockout ,我的代码可以正常工作。下面是我的表格。

<table class="tbl" id="dash" data-bind="sortTable: true">
<thead>
<tr class="tag close">
<th>Type</th>
<th>Title</th>
</tr>
</thead>
<tbody class="scrollContent" data-bind="foreach: Course">
<tr>
<td><i class="icon"></i></td>
<td><a href="#" id="qtipselector_01" data-bind="text: Title"></a></td>
<div id="TooltipContent_01" class="hidden">
<a> Test Tool Tip</a>
</div>
</div>
</tr>
</tbody>
</table>

最佳答案

这是一个示例:http://jsfiddle.net/jearles/RGsEH/

注意:JS 和 CSS 文件依赖项被引入到托管资源下。

HTML

<table data-bind="sortTable: true">
<thead>
<tr>
<th>Type</th>
<th>Title</th>
</tr>
</thead>
<tbody data-bind="foreach: course">
<tr>
<td data-bind="text: type"></td>
<td data-bind="text: title"></td>
</tr>
</tbody>
</table>

JS

function Course(type, title) {
this.type = type;
this.title = title;
}

var ViewModel = function() {
this.course = ko.observableArray([
new Course("type", "course1"),
new Course("another_type", "course2"),
new Course("second_type", "course5"),
new Course("third_type", "course4"),
new Course("fourth_type", "course3")
]);
}

ko.bindingHandlers.sortTable = {
init: function(element, valueAccessor) {
setTimeout( function() {
$(element).addClass('tablesorter');
$(element).tablesorter({widgets: ['zebra']});
}, 0);
}
};

ko.applyBindings(new ViewModel());

关于jquery - 如何使用带有 knockout 功能的 Jquery Table Sorter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14593367/

25 4 0