확실하지 않은 점은 무엇 이었습니까? 하지만 if 문을 사용하여 코드가 조금 더 정리되어 요소가 이미 추가되었는지 확인합니다.
그래서 내 마지막 코드는 이제 다음과 같습니다 : 모든 것이 완벽하게 작동
var $news_container = $('#news'); //The ID for the list with all the blog posts
$news_container.isotope({ //Isotope options, 'item' matches the class in the PHP
itemSelector: '.newsItem',
masonry: {
columnWidth: '.news-item-sizer',
gutter: '.gutter-sizer'
}
});
var is_appended = false;
$('button.showall').click(function(e) {
e.preventDefault();
var button = $(this);
// Record Nonce
var nonce = $(this).data("nonce");
if(is_appended == false) {
button.data('offset', $(this).data("offset"));
// Disable button
button.prop("disabled" , true);
// Set AJAX parameters
data = {
action: 'mft_load_more_ajax',
offset: button.data('offset'),
nonce: nonce
};
$.post(mft_load_more_ajax.ajaxurl, data, function(response) {
// Set Container Name
var response = JSON.parse(response);
console.log(response);
// Run through JSON
$.each(response, function(key, value) {
// Set Value
var val = $(value);
// Set Container
var $container = $('#news').isotope();
// Append Val
$container.append(val).isotope('appended', val);
});
// Undo Button Disable
button.prop("disabled" , false);
button.html('Weniger News anzeigen');
// Set Offset
// var offset = button.data("offset");
// button.data("offset", offset + 11);
// If Was appended
is_appended = true;
return false;
});
} else if(is_appended == true) {
$out = $('.newsItem.appendedItem');
$news_container.isotope('remove', $out)
// layout remaining item elements
.isotope('layout');
button.html('Alle News anzeigen');
is_appended = false;
return false;
}
});
크롬에서. 하지만 Firefox에서 Ajax 배열이 완전히 비어 있고 데이터를 가져올 수 없다는 것을 알아 냈습니다. 아마도 또 다른 문제는 별도로 게시 할 예정입니다.
문제가 고유합니까? 이 게시물을 확인 하시겠습니까? http://stackoverflow.com/questions/19485281/how-can-i-remove-all-images-and-add-a-new-list-of-images – mumair
감사합니다. @mumair, 저는 항목을 제거하는 데 도움이 필요하다고 생각하지 마십시오. 그건 내가 어떻게 든 할 수있는 일이다. 나는 이해하지 못한다. 왜 나는 심지어 그 기능에 들어갈 수 없다. 나는 뭔가를 간과해야합니다. – CaraMar
문제를 디버깅하기 위해'jsfiddle' 또는'plunker'를 제공 할 수 있습니까? – mumair