Bootstrap Popovers with ember.js template

后端 未结 5 1865
礼貌的吻别
礼貌的吻别 2021-02-06 08:44

I\'m trying to use Bootstrap Popover with EmberJS, so that the content of the popover will be a ember/handlebars template (with binding etc). How can this be done? (Ember 1.0.0-

5条回答
  •  梦如初夏
    2021-02-06 09:46

    I ran into this problem as well and had the same problem Robert mentioned above where the acceptable solution simply doesn't scale well to more complicated scenarios.

    I ran into a very elegant fix, but I'm not sure how future-friendly it is. I'm taking advantage of the function renderToBuffer - see below:

    //make your popover view to be created later
    App.PopoverView = Ember.View.extend({
      templateName : 'name-of-your-template-with-content'
    });
    
    //then you make your link that will trigger the popover
    App.PopoverLinkView = Ember.View.extend({
    
      tagName : 'a',
    
      didInsertElement : function(){
    
      var that = this;
    
      this.$().popover({
        'html' : true,
        'content' : function(el){
        var detailView = App.PopoverView.create();
        var html = detailView.renderToBuffer().buffer;
        return html;
        }
      });
    
      }
    
    });
    

    The advantage here is that you can pass in a model and make things dynamic. Haven't tested it thoroughly, but wanted to get this out there to potentially help others.

提交回复
热议问题