我試圖與savesort微件用的tablesorter。該表由knokout填充。的jQuery的tablesorter與淘汰賽 - 添加行
首次填充表,我得到正確的行量,而且記得排序。然後我用數據重新填充表,使用ajax並綁定到敲除數組。數據然後翻倍,但淘汰賽(正確),只追蹤一半的數據。
到目前爲止,我已經跟蹤它時,我應用保存在此方法排序:
self.tablesorter = function() {
$('table.tablesorterTranslation').trigger("update");
setTimeout(function() {
var sl = $.tablesorter.storage($('table.tablesorterTranslation'), 'tablesorter-savesort');
var sortList = (sl && sl.hasOwnProperty('sortList') && $.isArray(sl.sortList)) ? sl.sortList : '';
if (sortList && sortList.length > 0) {
// update sort change
$('table.tablesorterTranslation').trigger("sorton", [sortList]);
}
}, 1000);
return false;
};
這個方法被擊倒稱爲postaction結合。
在該方法被調用之前,我有一個表格用於挖空陣列中的每個項目,在postaction之後,我有兩個,一個被挖空跟蹤,一個似乎被tablesorter添加。
這是由於緩存的tablesorter值,並且是有辦法清洗嗎?
的HTML:
<table class="tablesorterTranslation" data-bind="visible: contents().length > 0">
<colgroup>
<col class="referencenumber"/>
<col class="title"/>
</colgroup>
<thead>
<tr>
<th class="referencenumber">Ref number</th>
<th class="title">Title</th>
</tr>
</thead>
<tbody data-bind="foreach: contents, postAction: tablesorter(), visible: contents().length > 0">
<tr>
<td class="referencenumber">
<span data-bind="text: contentReferenceNumber"></span>
</td>
<td class="title">
<a data-bind="attr: {href: previewUrl, title: previewTitle}, click: previewpopup" class="preview_translation"><%: AdminResources.Menu_Preview %></a>
</td>
</tr>
</tbody>
</table>
是重新填充表阿賈克斯:
self.setContentList = function() {
if ($('#LanguageIdNameValuePairs option').length > 0) {
self.contents.removeAll();
self.loading(true);
$.ajax('<%= Url.Action("GetContentList", "TranslateContentMenu") %>',
{
dataType: 'json',
data: {
languageId: $('#LanguageIdNameValuePairs').val(),
page: self.page
},
success: function (allData) {
var mappedContent = $.map(allData, function (item) { return new ContentViewModel(item); });
self.loading(false);
self.contents(mappedContent);
}
});
} else {
self.contents(new Array());
}
};
的contentviewmodel:
(function (ko) {
PODIUM.translation.ContentViewModel = function(data) {
this.contentReferenceId = ko.observable(data.contentReferenceId);
this.contentName = data.contentName;
this.previewUrl = ko.observable(data.previewUrl);
this.previewTitle = ko.observable(data.previewTitle);
this.publishTitle = ko.observable(data.publishTitle);
this.contentReferenceNumber = ko.observable(data.contentReferenceNumber);
};
}(ko));
和最後填充表和定義tablesort,與savesort (savingort是我認爲的問題)。
$('#OptionsMenu').change(function() {
viewModel.setContentList();
});
$('table.tablesorterTranslation').tablesorter({
widgets: ["saveSort"],
widgetOptions: {}
});
我有一個選擇列表,具有一定的價值,當這種變化,我從服務器獲取新的價值觀和重新填充表。這是它記住舊值的地方,但我想「清理」表並重新開始。
你有可以分享的現場演示嗎? – Mottie
不幸的是,它不是一個公共系統,我會看看我是否可以提供更多的代碼。 – ruffen