为什么在尝试刷新现有的accordion()时,accordion()不是一个函数?

时间:2015-12-30 21:03:00

标签: jquery wordpress jquery-ui jquery-ui-accordion

更新老实说,我不确定上下文是如何丢失的,但是在通过将所有jQuery('.sections')更改为var sections = jQuery('.sections')来强制显式上下文后,我可以更改所有{{1 }} jQuery('.parts')允许我再次使用accordion()。

以下是未来访问者的以下代码的工作版本......

jQuery('.parts', sections)

在嵌套手风琴中添加项目时,我无法刷新堆栈,因为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'); }); }); }); 已经成功调用两次。 You can see the .parts div has been initialized but still fails

根据我的理解,因为Unlike other widget methods, instance() is safe to call on any element after the accordion plugin has loaded.

,因此更不合理

这是在WordPress元数据框内运行的,并且所有脚本都正确加载了一个真正的方法来加载它们......

accordion() is not a function

以下是wp_enqueue_script('plugin-js', PLUGIN_ASSETS . 'js/metabox.js', ['jquery', 'jquery-ui-accordion', 'jquery-ui-sortable', 'jquery-ui-tabs'], false, false);的相关部分,其中包含了所有返回的错误,并且已删除......

metabox.js

这是通过AJAX ...

返回的标记的精简片段
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');
        });

    });

});

我很欣赏任何新鲜的眼睛,因为我已经用尽了我的搜索(这是由于依赖性破坏导致的类似错误,但实际情况并非如此)。

0 个答案:

没有答案