我有一个像这样的模板
<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可以有一些编码符号(如'
)
通常情况下,如果我在模板中使用#character,我会像\\#
一样进行转义。但是email_body来自数据库。
我该如何解决这个问题?
来自数据库的示例email_body
<p>http://www.revula.com/tto/admin/event/show/id/3</p><p>Linkte detayları verilen etkinliğe katılmak isteyen t&uuml;m personelin bilgisi i&ccedil;in &Ouml;zyeğin &Uuml;niversitesinden aldığım aşağıdaki mesajı paylaşıyorum.</p><div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;">Ekrem Bey Merhaba,</div><div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"><br clear="none" /></div><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;">Telefonda da bahsettiğim gibi eğitim verimliliğini arttırabilmek i&ccedil;in aşağıda linkini paylaştığım anketi ekip arkadaşlarınıza, eğitim &ouml;ncesi tamamlanması doğrultusunda iletebilirseniz &ccedil;ok seviniriz.</div><div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"><br clear="none" /></div><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;"><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">https://tr.surveymonkey.com/s/TargetEgitimi</a>&nbsp;</div><div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"><br clear="none" /></div><div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;"><br clear="none" /></div><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;">İyi &ccedil;alışmalar,</div><div style="font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;">Gizem Asker/&Ouml;z&Uuml;</div><div></div><p></p>
答案 0 :(得分:4)
我建议使用jQuery进行解码。您可以通过以下方式完成:
$("<div/>").html(subject).text()
这通过将jQuery附加到div
元素来使用jQuery,但由于它不是您网页的一部分,因此这不是问题,然后为其获取text
。
按照显示此方法的摘录
$(document).ready(function() {
var msg = "<p>http://www.revula.com/tto/admin/event/show/id/3</p><p>Linkte detayları verilen etkinliğe katılmak isteyen t&uuml;m personelin bilgisi i&ccedil;in &Ouml;zyeğin &Uuml;niversitesinden aldığım aşağıdaki mesajı paylaşıyorum.</p><div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'>Ekrem Bey Merhaba,</div><div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'><br clear='none' /></div><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;'>Telefonda da bahsettiğim gibi eğitim verimliliğini arttırabilmek i&ccedil;in aşağıda linkini paylaştığım anketi ekip arkadaşlarınıza, eğitim &ouml;ncesi tamamlanması doğrultusunda iletebilirseniz &ccedil;ok seviniriz.</div><div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'><br clear='none' /></div><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;'><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'>https://tr.surveymonkey.com/s/TargetEgitimi</a>&nbsp;</div><div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'><br clear='none' /></div><div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'><br clear='none' /></div><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;'>İyi &ccedil;alışmalar,</div><div style='font-family:'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:13px;background-color:#ffffff;'>Gizem Asker/&Ouml;z&Uuml;</div><div></div><p></p>";
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>