如果從Controller中的JSON對象填充項目,我試圖爲列表創建一個上一個和下一個按鈕。jQuery使用JSON和.NET MVC跳過並執行函數3
我有一個跳過和變量,以便我可以做同樣的記錄集。我想一次分七次前進(下一次),並一次倒退7次(前一次)。
訂單被正確加載,但我沒有完全理解跳過想法,以及在沒有更多「頁面」呈現時更改CSS類。
var skip = 0;
var take = 7;
function loadItems() {
$.ajax({
url: '@Url.Action("GetAllItems")',
data:
{
skip: skip,
take: take
},
type: "GET",
cache: false,
success: function (items) {
$.each(items, function (index, item) {
$('#ul-items').append('<li><a class="link">' + item.Information + '</a></li>');
});
}
});
}
$(document).ready(function() {
$('#previous').live("click", function() {
//page number , # of records needed
skip(0);
take(-7);
if (i) {//execute if there are no previous selections available
$('#previous').removeClass('enabled').addClass('disabled');
}
});
$('#next').live("click", function() {
//page number , # of records needed
skip(1);
take(7);
if (i) {//execute if there are no previous selections available
$('#next').removeClass('enabled').addClass('disabled');
}
});
});
也loadItems成功,你應該檢查,如果你收到最大項目(採取= 7所以7),如果沒有,你應該隱藏下一個按鈕。 – VinnyG