你好,
我在将 CSS 类 font-awesome 绑定到标签时遇到问题。
HTML:
<div class="flex-no-shrink">
<div class="btn-group">
<div data-bind="foreach: toolbarButtons">
<button type="button" class="btn btn-xs btn-primary" data-bind="enable: enabled, visible: visible, click: onClick">
<i class="fa" data-bind="css: { class: icon }"></i>
<!-- <i class="fa fa-plus"></i> -->
</button>
<button type="button" class="btn btn-xs btn-primary" data-bind="enable: enabled, visible: visible, click: onClick">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
</div>
TS:
interface IToolbarButton {
enabled: KnockoutComputed<boolean>;
visible: KnockoutComputed<boolean>;
icon: string;
onClick();
}
export abstract class ViewModel {
toolbarButtons: IToolbarButton[];
constructor(){
this.loadDefaultToolbar();
}
loadDefaultToolbar(): void {
this.toolbarButtons = [];
//add button
this.toolbarButtons.push({
enabled: knockout.pureComputed(() => true/*some internal logic*/),
icon: 'fa fa-plus',//this is what I want to place inside <i> tag
onClick: () => {/*some internal logic*/},
visible: knockout.pureComputed(() => true/*some internal logic*/)
});
//other default buttons...
}
};
ko.applyBindings(new ViewModel());
在我的情况下绑定的正确方法是什么?
我尝试了像text或css: { icon }这样的基本绑定,但它们现在也可以工作了。
感谢您的时间和帮助