Knockout自定义绑定 - 在bootstrap popover中显示图像?

时间:2013-06-04 23:55:35

标签: knockout.js

我有自定义绑定工作,排序:

http://jsfiddle.net/PTSkR/115/

popover有效但内容是链接,而不是图像本身。如何让图像显示在弹出窗口中?

代码:

ko.bindingHandlers.bootstrapPopover = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
        var options = valueAccessor();
        var defaultOptions = {trigger: 'hover'};
        options = $.extend(true, {}, defaultOptions, options);
        $(element).popover(options);
    }
};
var viewModel = {
    sideOneTextContent: ko.observable('<img src="https://si0.twimg.com/a/1339639284/images/three_circles/twitter-bird-white-on-blue.png" />')
}
ko.applyBindings(viewModel);

1 个答案:

答案 0 :(得分:1)

您需要在元素绑定中添加'html:true'选项。见this update of your jsfiddle

<a class="image-content-saved" href="#" data-bind="bootstrapPopover: { content: sideOneTextContent(), html:true }">
    <img src="http://www.dailydesigninspiration.com/diverse/adv/publicis/Omax-Wide-Angle-Lenses.jpg" />
</a>