所以我有一个switch case函数,它返回多个选项,我试图在各种敲除绑定中引用每个选项,但是它不起作用?
function messageIcon (type) {
return ko.computed(function () {
switch (type) {
case InteractionMessageTypes.Customer:
return {
tooltip: "This message was sent by the customer",
icon: "icon icon-user4",
contentClass: "customer-message"
};
case InteractionMessageTypes.Agent:
return {
tooltip: "This message was sent by an agent",
icon: "icon icon-headset",
contentClass: "agent-message"
};
case InteractionMessageTypes.Initiate:
return {
tooltip: "This session has started",
icon: "icon icon-phone2",
contentClass: "system-message"
};
<div data-bind="css: messageIcon($data.contentClass)">
<span data-bind="css: messageIcon($data.icon), attr:{title: messageIcon($data.tooltip)}"></span>
</div>
答案 0 :(得分:0)
解决此问题的方法是将每种情况下的收益都更改为
return {
tooltip: "This message was sent by the customer",
icon: "icon icon-user4",
contentClass: "customer-message"
};
到
return '<span class="icon icon-user customer-message" title="This message was sent by the customer">' + '</span>';
}
然后像这样将数据绑定html
<span data-bind="html: messageIcon($data.Type)">
</span>