Jquery 为什么尝试刷新现有accordion()时accordion()不是函数?
UPDATE老实说,我不确定上下文是如何丢失的,但是在通过将所有Jquery 为什么尝试刷新现有accordion()时accordion()不是函数?,jquery,wordpress,jquery-ui,jquery-ui-accordion,Jquery,Wordpress,Jquery Ui,Jquery Ui Accordion,UPDATE老实说,我不确定上下文是如何丢失的,但是在通过将所有jQuery('.sections')更改为var sections=jQuery('.sections')强制显式上下文之后,我可以使用accordion()又一次 这是下面代码的工作版本,供将来的访问者使用 jQuery(document).ready(function(){ var layout_sections = jQuery('.sections'); /* retrieve the settings
jQuery('.sections')
更改为var sections=jQuery('.sections')
强制显式上下文之后,我可以使用accordion()又一次
这是下面代码的工作版本,供将来的访问者使用
jQuery(document).ready(function(){
var layout_sections = jQuery('.sections');
/* retrieve the settings fields markup via AJAX. */
jQuery.post(ajaxurl, {}, function(response){
layout_sections.append(response).accordion({
active: false,
collapsible: true,
heightStyle: 'content',
header: '> .section > .section-title'
}).sortable({
axis: 'y',
handle: '.section-title',
stop: function(e, ui){
ui.item.children('.section-title').triggerHandler('focusout');
}
});
jQuery('.parts', layout_sections).accordion({
active: false,
collapsible: true,
heightStyle: 'content',
header: '> .part > .part-title'
}).sortable({
axis: 'y',
handle: '.part-title',
stop: function(e, ui){
ui.item.children('.part-title').triggerHandler('focusout');
}
});
});
jQuery(document).on('click', '.do-new-section', function(e){
jQuery.post(ajaxurl, {}, function(response){
layout_sections.append(response).accordion('refresh');
jQuery('.parts', layout_sections).accordion({
active: false,
collapsible: true,
heightStyle: 'content',
header: '> .part > .part-title'
}).sortable({
axis: 'y',
handle: '.part-title',
stop: function(e, ui){
ui.item.children('.part-title').triggerHandler('focusout');
}
});
});
}).on('click', '.do-new-part', function(e){
var parts_target = jQuery('#parts-id', layout_sections);
jQuery.post(ajaxurl, {}, function(response){
parts_target.append(response).accordion('refresh');
});
});
});
在向嵌套的accordion添加项目时,我无法刷新堆栈,因为
accordion()不是函数
,尽管它已经被成功调用了两次
根据我的理解,这更不合理,因为
这是在WordPress元数据库中运行的,所有脚本都使用一个真正的加载方法正确加载
wp_-enqueue_脚本('plugin-js',plugin_-ASSETS.'js/metabox.js',['jquery','jqueryui-accordion','jqueryui-sortable','jqueryui-tabs',false,false)代码>
以下是metabox.js
的相关部分,其中包含所有返回错误,并删除了这些错误
jQuery(document).ready(function(){
/* retrieve the settings fields markup via AJAX. */
jQuery.post(ajaxurl, {}, function(response){
jQuery('.sections').append(response).accordion({
active: false,
collapsible: true,
heightStyle: 'content',
header: '> .section > .section-title'
}).sortable({
axis: 'y',
handle: '.section-title',
stop: function(e, ui){
ui.item.children('.section-title').triggerHandler('focusout');
}
}).find('.parts').accordion({
active: false,
collapsible: true,
heightStyle: 'content',
header: '> .part > .part-title'
}).sortable({
axis: 'y',
handle: '.part-title',
stop: function(e, ui){
ui.item.children('.part-title').triggerHandler('focusout');
}
});
});
jQuery(document).on('click', '.do-new-section', function(e){
jQuery.post(ajaxurl, {}, function(response){ jQuery('.sections').append(response).accordion('refresh').find('.parts').accordion({
active: false,
collapsible: true,
heightStyle: 'content',
header: '> .part > .part-title'
}).sortable({
axis: 'y',
handle: '.part-title',
stop: function(e, ui){
ui.item.children('.part-title').triggerHandler('focusout');
}
});
});
}).on('click', '.do-new-part', function(e){
/* This is there I'm having issues calling accordion(), the function just doesn't exist when referencing the desired element. */
var parts_target = jQuery(this).parents('.section-fields').find('.parts');
jQuery.post(ajaxurl, {}, function(response){
parts_target.append(response).accordion('refresh');
});
});
});
下面是通过AJAX返回的标记的精简片段
<div class="sections">
<div class="section">
<div class="section-title">
Banner Slideshow
</div>
<div class="section-fields">
<a class="do-new-part" href="#">
Add slides
</a>
<div class="parts">
<div class="part">
<div class="part-title">
Slide
</div>
<div class="part-fields">
Slide fields
</div>
</div>
</div>
</div>
</div>
</div>
横幅幻灯片
滑动
幻灯片区
我希望大家能重新审视这一点,因为我已经用尽了我的搜索(这是一个类似的错误,是由断开的依赖项引起的,事实并非如此) 尝试在第一次调用后直接通过.accordion(“实例”)
将每个accordion
保存到变量中。在点击处理程序中检查它们会很有用。谢谢你的提醒,但我都没能做到。当从AJAX响应调用时,顶级accordion初始化很好,但在我有layout_节之后立即进行。find('.parts')。each(function(){var parts=jQuery(this).accordion('instance');accordions.push(parts);})
和getaccordion不是一个函数
。accordion API声明:检索accordion的实例对象。如果元素没有关联的实例,则返回undefined。
这应该返回undefined
notaccordion不是函数。你确定手风琴图书馆还在使用中吗?你刚刚帮我解决了几个星期来一直困扰我的问题。我修改了代码,在选择器中使用上下文,这似乎解决了问题。请继续浏览互联网,告诉人们检查上下文。非常感谢你,亲爱的。脏ole上下文。