我已经使用Ajax实时更新为我的投资组合实现了多级过滤器,我的投资组合是一个可扩展的div,它将使用这个jQuery代码运行
$(function() {
Grid.init();
});
相关代码
var Grid = (function() {
// list of items
var $grid = $( '#og-grid' ),
// the items
$items = $grid.children( 'li' ),
// current expanded item's index
current = -1,
// position (top) of the expanded item
// used to know if the preview will expand in a different row
previewPos = -1,
// extra amount of pixels to scroll the window
scrollExtra = 0,
// extra margin when expanded (between preview overlay and the next items)
marginExpanded = 10,
$window = $( window ), winsize,
$body = $( 'html, body' ),
// transitionend events
transEndEventNames = {
'WebkitTransition' : 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd',
'msTransition' : 'MSTransitionEnd',
'transition' : 'transitionend'
},
transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
// support for csstransitions
support = Modernizr.csstransitions,
// default settings
settings = {
minHeight : 350,
speed : 350,
easing : 'ease'
};
function init( config ) {
// the settings..
settings = $.extend( true, {}, settings, config );
// preload all images
$grid.imagesLoaded( function() {
// save item´s size and offset
saveItemInfo( true );
// get window´s size
getWinSize();
// initialize some events
initEvents();
} );
}
Ajax Call
// AJAX update
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'update':
require __DIR__ . '/portfolio--results.php';
break;
}
die( 0 );
}
function update_results() {
var $form = $(this).parents("form");
var data = $form.serializeArray();
data.push({
name: "action",
value: "update"
});
$.ajax({
type : "GET",
data : data,
success : function(response) {
$(".search-results").html(response);
}
});
}
事件监听器
$(document).on("click", "menu:not(:last-child) input", update_results);
$(document).on("click", "menu:not(:first-child) input", update_results);
页面运行良好,直到我使用Ajax加载数据,组合功能将破裂。 我知道有一种方法来委托jQuery代码来修复Ajax问题,但是我对jQuery不是很熟悉,有人能帮我解决这个问题吗?
我将代码复制并粘贴到Ajax正在加载该广告的页面上,它只运行一次,并在选择更多过滤器后中断。