Kendo ui模板不支持html编码符号

时间:2014-12-11 10:12:31

标签: kendo-ui kendo-template

我有一个像这样的模板

<script type="text/x-kendo-template" id="email-view-template">
    <div>#=email_subject#</div>
    <div>#=email_body#</div>
</script>

值来自数据库(email_subject和email_body)。因为email_body kendo模板不起作用。 email_body可以有一些编码符号(如&#39;

通常情况下,如果我在模板中使用#character,我会像\\#一样进行转义。但是email_body来自数据库。

我该如何解决这个问题?

来自数据库的示例email_body

&lt;p&gt;http://www.revula.com/tto/admin/event/show/id/3&lt;/p&gt;&lt;p&gt;Linkte detayları verilen etkinliğe katılmak isteyen t&amp;uuml;m personelin bilgisi i&amp;ccedil;in &amp;Ouml;zyeğin &amp;Uuml;niversitesinden aldığım aşağıdaki mesajı paylaşıyorum.&lt;/p&gt;&lt;div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;Ekrem Bey Merhaba,&lt;/div&gt;&lt;div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;&lt;br clear="none" /&gt;&lt;/div&gt;&lt;div id="yui_3_16_0_1_1418222798054_35228" style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;Telefonda da bahsettiğim gibi eğitim verimliliğini arttırabilmek i&amp;ccedil;in aşağıda linkini paylaştığım anketi ekip arkadaşlarınıza, eğitim &amp;ouml;ncesi tamamlanması doğrultusunda iletebilirseniz &amp;ccedil;ok seviniriz.&lt;/div&gt;&lt;div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;&lt;br clear="none" /&gt;&lt;/div&gt;&lt;div id="yui_3_16_0_1_1418222798054_35230" style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;&lt;a href="https://tr.surveymonkey.com/s/TargetEgitimi" id="yui_3_16_0_1_1418222798054_35229" rel="nofollow" shape="rect" style="margin:0px;padding:0px;background-color:transparent;color:purple;outline:none;" target="_blank"&gt;https://tr.surveymonkey.com/s/TargetEgitimi&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;&lt;br clear="none" /&gt;&lt;/div&gt;&lt;div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;&lt;br clear="none" /&gt;&lt;/div&gt;&lt;div id="yui_3_16_0_1_1418222798054_35216" style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;İyi &amp;ccedil;alışmalar,&lt;/div&gt;&lt;div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"&gt;Gizem Asker/&amp;Ouml;z&amp;Uuml;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;

1 个答案:

答案 0 :(得分:4)

我建议使用jQuery进行解码。您可以通过以下方式完成:

$("<div/>").html(subject).text()

这通过将jQuery附加到div元素来使用jQuery,但由于它不是您网页的一部分,因此这不是问题,然后为其获取text

按照显示此方法的摘录

$(document).ready(function() {
  var msg = "&lt;p&gt;http://www.revula.com/tto/admin/event/show/id/3&lt;/p&gt;&lt;p&gt;Linkte detayları verilen etkinliğe katılmak isteyen t&amp;uuml;m personelin bilgisi i&amp;ccedil;in &amp;Ouml;zyeğin &amp;Uuml;niversitesinden aldığım aşağıdaki mesajı paylaşıyorum.&lt;/p&gt;&lt;div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;Ekrem Bey Merhaba,&lt;/div&gt;&lt;div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;&lt;br clear='none' /&gt;&lt;/div&gt;&lt;div id='yui_3_16_0_1_1418222798054_35228' style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;Telefonda da bahsettiğim gibi eğitim verimliliğini arttırabilmek i&amp;ccedil;in aşağıda linkini paylaştığım anketi ekip arkadaşlarınıza, eğitim &amp;ouml;ncesi tamamlanması doğrultusunda iletebilirseniz &amp;ccedil;ok seviniriz.&lt;/div&gt;&lt;div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;&lt;br clear='none' /&gt;&lt;/div&gt;&lt;div id='yui_3_16_0_1_1418222798054_35230' style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;&lt;a href='https://tr.surveymonkey.com/s/TargetEgitimi' id='yui_3_16_0_1_1418222798054_35229' rel='nofollow' shape='rect' style='margin:0px;padding:0px;background-color:transparent;color:purple;outline:none;' target='_blank'&gt;https://tr.surveymonkey.com/s/TargetEgitimi&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;&lt;br clear='none' /&gt;&lt;/div&gt;&lt;div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;&lt;br clear='none' /&gt;&lt;/div&gt;&lt;div id='yui_3_16_0_1_1418222798054_35216' style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;İyi &amp;ccedil;alışmalar,&lt;/div&gt;&lt;div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'&gt;Gizem Asker/&amp;Ouml;z&amp;Uuml;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;";
  var decoded = $("<div/>").html(msg).text();
  
  console.log("decoded", decoded);
  var model = kendo.observable({
    email_subject : "This is the subject",
    email_body : decoded
  });

  var tmpl = kendo.template($("#template").html());
  $("#tgt_template").html(tmpl(model));
});
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.mobile.all.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.web.min.js"></script>

<script type="text/x-kendo-template" id="template">
  <div>
  	<div>Subject: #=email_subject#</div>
    <div>#=email_body#</div>
  </div>
</script>


<div id="tgt_template"></div>