how can I invoke an ember component dynamically via a variable?

前端 未结 4 547
感动是毒
感动是毒 2020-12-01 09:36

Lets say I have an array of widget objects on my controller and each widget object has member variable that is assigned the name of a component class. How can I get my temp

4条回答
  •  日久生厌
    2020-12-01 10:11

    I tried this and it seems to work, but its just a lot of guesswork on my part:

    Ember.Handlebars.registerHelper('renderComponent', function(componentPath, options) {
      var component = Ember.Handlebars.get(this, componentPath, options),
          helper = Ember.Handlebars.resolveHelper(options.data.view.container, component);
    
      helper.call(this, options);
    
    });
    

    and you use it the same way:

    {{#each widget in widgets}}
      {{renderComponent widget.componentClass widget=widget}}
    {{/each}}
    

提交回复
热议问题