inline javascript within handlebars template

后端 未结 1 1575
甜味超标
甜味超标 2021-01-08 01:10

Is there no way to have an inline script within a Handlebars template?



        
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-08 01:44

    You'll have to wrap that widget in a custom Ember.View to handle instantiating it and adding it to the DOM, in the wrapper view's didInsertElement. Ember expects, especially inside handlebars templates, to have full control over DOM manipulation, and it does that with a combination of handlebars magic, and Ember.View creation. Once you've defined your customview:

    MyApp.DisqusView = Em.View.extend({
        didInsertElement: function() {
            // create widget and append it to this.$()
        }
    });
    

    You can use it in your handlebars template:

    {{view MyApp.DisqusView}}
    

    Your view should not add Script tags, for safety reasons, but should rather execute any JS directly to insert the widget.

    0 讨论(0)
提交回复
热议问题