web-dev-qa-db-ja.com

不明なTypeError:$ template.getは関数ではありません

WpBakery Visual Composerというプラグインを使用している場合、WordPressでこのエラーが発生します。

最新バージョンのWordPress(4.5)を使用しています。最新のGoogle Chromeバージョンを使用しており、すべてのプラグインが更新されています。 Visual Composerを使用して要素またはテンプレートを追加できないようです。

誰かが私を助けたり、何が起こっているのか、このエラーを修正する方法を教えてもらえますか?.

私が得るエラー:

enter image description here

39
roykasa

私の答えをご覧ください こちら

html2element関数を次のように更新して、このバグを修正しました。

html2element: function(html) {
        var $template, attributes = {},
            template = html;
        $template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
            attributes[attr.name] = attr.value
        }), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
    },

/wp-content/plugins/js_composer/assets/js/backend/composer-view.js

またはwp-content/plugins/js_composer/assets/js/dist/backend.min.js`

これがあなたのために働くことを望みます!

98
Ben

@ソリン・ハイダウ

こんにちは皆さん、私はAstraテーマを使用しています。この修正は、99.9%動作しています。いくつかのトーでは、これはスピニングホイールを停止するだけですが、ページが視覚的に読み込まれるとcomposerは停止しません。

このコードにわずかな変更を加えました(今ではどこにでも投稿されています)

オリジナルのAstraテーマコードはこちら(composer-view.js)

        html2element:function (html) {
        var attributes = {},
            $template;
        if (_.isString(html)) {
            this.template = _.template(html);
            $template = $(this.template(this.model.toJSON()).trim());
        } else {
            this.template = html;
            $template = html;
        }
        _.each($template.get(0).attributes, function (attr) {
            attributes[attr.name] = attr.value;
        });
        this.$el.attr(attributes).html($template.html());
        this.setContent();
        this.renderContent();
    },

動作するコード:

html2element: function(html) {
    var $template, 
    attributes = {},
    template = html;
    $template = $(template(this.model.toJSON()).trim()), 
     _.each($template.get(0).attributes, function(attr) {
    attributes[attr.name] = attr.value
}); this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
},

主な違いはここにあります(元のコードに対して)

}); this.$el.attr

元のコンマの代わりにセミコロンがあります:):

}), this.$el.attr

乾杯!

更新:これは、上記と同じエラーでテーマastraを使用していた20のサイトのうち約19を修正しました... 1つのサイトを除くすべて。

ビジュアルcomposerが最終的に表示された後にこのエラーが発生しました(設計要素の半分が欠落しています)

Uncaught Error: Syntax error, unrecognized expression: .ui-tabs-nav [href=#tab-1415196282-1-8]

Composer-custom-views.jsの552行を更新することでこれを修正しました:

$('.ui-tabs-nav [href="#tab-' + params.tab_id + '"]').text(params.title);

そして、すべてが機能するようになりました。すべてのテーマで機能しない場合は申し訳ありませんが、上記の他の人が言及したコードを使用してみてください。それがうまくいかない場合は、私の解決策を試してください:)

21
Renegade_Mtl

誰かがWordPressフォーラムにこのソリューションを投稿してくれました。

html2element/wp-content/plugins/js_composer/assets/js/backend/composer-view.js関数を次のものに置き換えます。

html2element: function(html) {
            var $template, attributes = {},
                template = html;
            $template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
                attributes[attr.name] = attr.value
            }), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
        },

編集:さまざまな状況下でこの置換を2回行う必要があり、Visual Composerプラグインの両方を無効にしてから再度有効にするまで動作しませんでしたand Ultimate Visual Composerアドオン。

16
Elon Zito

コードはhtml2element関数に渡されていませんが、それを呼び出す関数に存在していることに注意してください(レンダリング)

次のコードは私の問題を完全に修正しました。ページの読み込み、追加、複製、削除などができます。

render: function () {
                        var $shortcode_template_el = $( '#vc_shortcode-template-' + this.model.get( 'shortcode' ) );
                        if ( $shortcode_template_el.is( 'script' ) ) {
                                var newHtmlCode =  _.template( $shortcode_template_el.html(),
                                                                                                this.model.toJSON(),
                                                                                                vc.templateOptions.default );
                                if(!_.isString(newHtmlCode)){
                                        newHtmlCode = $shortcode_template_el.html();
                                }
                                this.html2element( newHtmlCode );
                        } else {
                                var params = this.model.get( 'params' );
                                $.ajax( {
                                        type: 'POST',
                                        url: window.ajaxurl,
                                        data: {
                                                action: 'wpb_get_element_backend_html',
                                                data_element: this.model.get( 'shortcode' ),
                                                data_width: _.isUndefined( params.width ) ? '1/1' : params.width,
                                                _vcnonce: window.vcAdminNonce
                                        },
                                        dataType: 'html',
                                        context: this
                                } ).done( function ( html ) {
                                        this.html2element( html );
                                } );
                        }
                        this.model.view = this;
                        this.$controls_buttons = this.$el.find( '.vc_controls > :first' );
                        return this;
                },
2
Amritosh pandey

面白いことに...私の視覚的なcomposerバージョン番号は、最新の更新(4.8。*)を大きく上回っていました。

とにかく...私はこの同じ問題を抱えていて、それらの以前の答えは完全に私の問題を解決しなかったので、プラグインの新しいコピーを試して購入することにしました。うまくいきました。

Visual Composerバージョン4.12.1がWordPress 4.6.1でエラーなく動作することを確認できました。

これにも注意してください:

Visual Composerの最新バージョンには、backendcomposer-view.jsというファイルはありません。

PS。これらのGUIページビルダーを使用するのは面倒です***。

2
Shamppi

これはWordPressバージョン4.9.8で機能しました

html2element:function (html) {
    var attributes = {}, 
        $template;
    if (_.isString(html)) {
        this.template = _.template(html);
    } else {
        try {
            this.template = _.template(html());                                                                                                                          
        } catch (err) {
            this.template = html;
        }   
    }   
    $template = $(this.template(this.model.toJSON()).trim());
    _.each($template.get(0).attributes, function (attr) {
        attributes[attr.name] = attr.value;
    }); 
    this.$el.attr(attributes).html($template.html());
    this.setContent();
    this.renderContent();
},
0
PKInd007

visual composerの2016年12月の最新の修正はこれです。

html2element:function(html){var $template,attributes={},template=vc.template(html);$template=$(template(this.model.toJSON()).trim()),_.each($template.get(0).attributes,function(attr){attributes[attr.name]=attr.value}),this.$el.attr(attributes).html($template.html()),this.setContent(),this.renderContent()},

この重要なことに注意してくださいtemplate = vc.template(html);実際のコードでは。これは、WPordpressの最新版と互換性のある最新バージョンのクイックフィックスです。

それに応じてWordpressとテーマを更新することを忘れないでください。したがって、この修正は問題なく機能するはずです。

おかげで幸せなコーディング

0
mindlogixtech