Knockout Twitter Bootstrap Popover Binding

前端 未结 4 1792
礼貌的吻别
礼貌的吻别 2020-12-31 20:38

I am trying to create a custom binding for twitter boostrap popovers that references a template but I am having trouble with the binding part of the content inside of the po

4条回答
  •  生来不讨喜
    2020-12-31 20:46

    I adapted another answer here: https://stackoverflow.com/a/16876013/1061602

    This works a lot better for me, especially for a simple popover.

    ko.bindingHandlers.popover = {
        init: function (element, valueAccessor) {
            var local = ko.utils.unwrapObservable(valueAccessor()),
                options = {};
    
            ko.utils.extend(options, ko.bindingHandlers.popover.options);
            ko.utils.extend(options, local);
    
            $(element).popover(options);
    
            ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
                $(element).popover("destroy");
            });
        },
        options: {
            placement: "top"
        }
    };
    

    Then the binding is:

    
    

    You can override other options obviously.

提交回复
热议问题