如何在asp.mvc中的剑道聊天中渲染消息附件中将文本渲染为html?

问题描述 投票:0回答:1

我正在 asp.net mvc 中使用 kendo.ui.Chat api,并且我想将 renderMessage 方法中的文本功能呈现为 HTML,但目前尚未呈现。

输入:

chat.renderMessage(
                      {
                        type: "text",
                        text: "<h1> Hello </h1>",
                       },
                        userInfo
                  );

输出:

<h1> Hello </h1>

但我需要输出为:Hello

javascript asp.net-mvc kendo-grid chatbot kendo-ui-mvc
1个回答
0
投票

您可能必须使用 html 标签模板才能工作。

示例

<script id="custom-template" type="text/x-kendo-template">
   <div class="#=styles.message#">
      <time class="k-message-time">#= kendo.toString(kendo.parseDate(timestamp), "dd-MMM-yyyy HH:mm:ss") #</time>
    <div class="k-chat-bubble">#=text#</div>
  </div>
</script>

还有

<script>
      var CUSTOM_TEMPLATE = kendo.template($('#custom-template').html());
      kendo.chat.registerTemplate("custom", CUSTOM_TEMPLATE);     

      var chat = $("#chat").kendoChat().data("kendoChat");  

      chat.renderMessage({
        type: "custom",
        text: "<h1>How may I help you</h1>!!!"
      }, { name: "The other user" }); 

      chat.renderMessage({
        type: "custom",
        text: "Help me find John Doe"
      }, chat.getUser()); 

</script>

参考资料:https://docs.telerik.com/kendo-ui/api/javascript/ui/chat/methods/rendermessage

© www.soinside.com 2019 - 2024. All rights reserved.