几周前,我在我的 WordPress 网站上添加了一些同位素,并且一切正常。然而,在对网站进行一些更改后,我现在收到一条错误消息,并且真的很难找出导致该错误的原因,因为相同的代码在 JSFiddle 中工作正常,例如。 http://jsfiddle.net/ttf5776r/12/
我在网站上时在错误控制台中收到的错误消息是:
TypeError: i.data(...) is undefined ...)n[t]=s||"original-order"!==t?rt:i.data(this,"isotope-sort-data")[t];i.da...
我发现,如果删除以下代码,错误消息将停止出现,并且同位素可以工作,但由于代码已被删除,因此不会将选定的框放入左上角。
$container
.isotope( 'updateSortData', $this.parent() ) //this should be above the 'return false;' to make the selected photo go to top left corner but it decided to break and havem't had time to find fix. - LOL 08-01-2015
.isotope( 'updateSortData', $previousSelected )
.isotope();
不幸的是,我不记得自此生效以来我所做的所有更改,但我很确定没有对 JQuery 进行任何修改。
谁能帮我解决问题吗?
代码如下:
函数.php
function add_isotope() {
wp_register_script('isotope', 'http://isotope.metafizzy.co/v1/jquery.isotope.min.js', array('jquery'));
wp_enqueue_script('isotope');
}
add_action( 'wp_enqueue_scripts', 'add_isotope' );
function add_jsscripts() {
wp_register_script('jsscripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'));
wp_enqueue_script('jsscripts');
}
add_action( 'wp_enqueue_scripts', 'add_jsscripts' );
最佳答案
您的错误涉及缩小的源。第一步是切换到使用非缩小源,以便变量具有其原始名称。
此时您会发现错误(“key”变为“t”等):
updateSortData : function( $atoms, isIncrementingElemCount ) {
var instance = this,
getSortData = this.options.getSortData,
$this, sortData;
$atoms.each(function(){
$this = $(this);
sortData = {};
// get value for sort data based on fn( $elem ) passed in
for ( var key in getSortData ) {
if ( !isIncrementingElemCount && key === 'original-order' ) {
// keep original order original
sortData[ key ] = $.data( this, 'isotope-sort-data' )[ key ];
} else {
sortData[ key ] = getSortData[ key ]( $this, instance );
}
}
// apply sort data to element
$.data( this, 'isotope-sort-data', sortData );
});
},
您收到的错误“i.data() is undefined”因此变为“$.data() is undefined”——这似乎表明 .data()
插件是未正确加载,或者(更有可能)传递给 isotope 的变量实际上并不是 jQuery 库的句柄。检查如何加载和初始化同位素。
关于javascript - jQuery 同位素错误。停止在 WordPress 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27845510/