开发者

How to fix HTML from WCF-webservice in AJAX Client Side-templates

I have a problem with my templates, when I return HTML, it's encoded by default, and I cannot find a way to "fix" it.

I want to replace NewLines (开发者_如何学Go\u000a) with a straight <br />, but I always end up with &amp;lt;br&amp;gt;

I've tried to fix it with this function:

function cleanNewLines(text)
{
   return $("<div>" + text.replace(/\u000a/ig, "<br />") + "</div>").html();
}

But without any luck.

I call bind the template with: {{cleanNewLines(NoteText)}}

What I am trying to accomplish is the ability to render HTML with client-side templates, so if my database contains newlines, I want to be able to replace them with a <br />-tag

So if my database contains the string Hi\u000aThis is a test, I want to replace the \u000a with a <br />, so that the string would be Hi<br />This is a test


I fixed this by taking the data-container into consideration:

function cleanNewLines(sender, args) 
{
    var data = $("#divNotes");
    data.html(data.html().replace(/\u000a/ig, "<br />"));
}

So when I call the dataview:onrendered I added the cleanNewLines-function and it replaced all newlines (even the ones it shouldn't replace), but I just removed the newlines from the original html and that solved it.

Note: I use jQuery to get the .html()-function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜