使用Javascript - 如何逃脱剑道模板双人和单引号 [英] Javascript - How to escape double and single quotes on Kendo template
问题描述
我用我的kendolistview视图页面(剃刀)上。里面的剑道模板我有这个code。它只是打开引导弹出用。问题是内容的数据有一定的和的值。所以,链接无法被称为JS的功能,弹出无法打开。
我试图在数据层替换引号:
内容= rss.CONTENT.Replace(@\\,,\\),更换(',@\\')
摘要= rss.SUMMARY.Replace(@\\,,\\),更换(',@\\')
查看
@model AIS.UI.WebService.Proxy.DSrvAllService.NewsItem
@using Kendo.Mvc.UI @(Html.Kendo()的ListView< AIS.UI.WebService.Proxy.DSrvAllService.NewsItem>()
。名称(ListView控件)
.TagName(格)
.ClientTemplateId(模板)
.DataSource(数据源=>数据源
。型号(型号=> model.Id(ID))
.ServerOperation(真) .PageSize(2)
.Events(事件=> events.Error(onError的))
.Read(读=> read.Action(GetNewsList,新闻报)) )
.Pageable()
) <脚本类型=文/ X-剑道模板ID =模板>
....
<一
HREF =JavaScript的:openNewsPopup('#:标题1#,#:摘要#,#:内容#,#:IMAGEURL#,#:时间#
','#:ADDDATE#,#:AddYear#,#:SubmitedBy#')级=BTN右拉式><跨度风格=字体 -
重量:正常的rel =工具提示标题=了解更多关于公布>了解详情< / SPAN>< / A> <脚本>
的js(视图模型)
VAR OpenNewsPopupViewModel =功能(){
VAR自我=这一点; self.Title = ko.observable();
self.Summary = ko.observable();
self.Content = ko.observable();
self.ImageURL = ko.observable();
self.AddTime = ko.observable();
self.AddDate = ko.observable();
self.AddYear = ko.observable();
self.SubmitedBy = ko.observable();
self.ImageURLFull = ko.observable();
}; VAR openNewsPopupViewModel = NULL;功能openNewsPopup(pTitle,pSummary,pContent,pImageURL,pAddTime,pAddDate,pAddYear,pSubmitedBy){
VAR imageRootPath ='@ Url.Content(〜/图片/公告/ NewsTypes / NewsType)'; VAR isNewViewModel =(openNewsPopupViewModel == NULL); VAR newsPopup = $(#newsPopup); 如果(isNewViewModel)
{
openNewsPopupViewModel =新OpenNewsPopupViewModel(); 变种newsPopupTag = newsPopup.get()[0];
ko.applyBindings(openNewsPopupViewModel,newsPopupTag);
} // pContent = str.replace(/ \\/ g的,\\\\\\);
openNewsPopupViewModel.Title(pTitle);
openNewsPopupViewModel.Summary(pSummary);
openNewsPopupViewModel.Content(pContent);
openNewsPopupViewModel.ImageURL(pImageURL);
openNewsPopupViewModel.AddTime(pAddTime);
openNewsPopupViewModel.AddDate(pAddDate);
openNewsPopupViewModel.AddYear(pAddYear);
openNewsPopupViewModel.SubmitedBy(pSubmitedBy);
openNewsPopupViewModel.ImageURLFull();
openNewsPopupViewModel.ImageURLFull(imageRootPath + + openNewsPopupViewModel.ImageURL()+'.JPG''。');
newsPopup.modal('秀');
}
的样本数据(即应更换双引号)
< A HREF =JavaScript的:openNewsPopup('1版发布,1.0版
现在在网上提供。您可以下载的新版本
客户端程序从网站的http:=255.255.255.0 =测试=或=
安装=程序=能=自动=下载=它=为=
你','新闻=上下文=会=被=摆=在这里。=新闻==
,更新,12:04,='01 0.01','2013','管理')=级=BTN右拉式><跨度
风格=字体重量:正常的rel =提示标题=了解更多有关
公布>了解详情< / SPAN>< / A>
您送他们到客户端之前,需要连接code中的字符串。如果在一个的Razor视图设置字符串,你可以简单地调用 @ Html.En code(串)
。要带code剃刀视图之外的内容(例如,在数据访问code),只需要调用的 System.Web.HttpUtility.HtmlEn code(串)
直接。
HttpUtility.HtmlEn code(一个简单的'恩codeD'\\字符串\\);
//一个简单的&放大器;#39; EN coded和放大器;#39; &安培; QUOT;串和放大器。QUOT;
I'm using kendolistview on my view page(razor). Inside of the kendo template I have this code. It just opens the bootstrap pop-up with. Problem is the "content" data has some " and ' values. So the link cannot be referred to the js function and the pop-up doesn't open.
I tried replacing the quotes in the data layer:
Content = rss.CONTENT.Replace(@"\""", "\"").Replace("'", @"\'")
Summary = rss.SUMMARY.Replace(@"\""", "\"").Replace("'", @"\'")
View
@model AIS.UI.WebService.Proxy.DSrvAllService.NewsItem
@using Kendo.Mvc.UI
@(Html.Kendo().ListView<AIS.UI.WebService.Proxy.DSrvAllService.NewsItem>()
.Name("listView")
.TagName("div")
.ClientTemplateId("template")
.DataSource(dataSource => dataSource
.Model(model =>model.Id("ID"))
.ServerOperation(true)
.PageSize(2)
.Events(events => events.Error("onError"))
.Read(read => read.Action("GetNewsList", "News"))
)
.Pageable()
)
<script type="text/x-kendo-template" id="template">
....
<a
href="javascript:openNewsPopup('#:Title1#','#:Summary#','#:Content#','#:ImageURL#','#:AddTime#
','#:AddDate#','#:AddYear#','#:SubmitedBy#')" class="btn pull-right"><span style="font-
weight:normal" rel="tooltip" title="Read more about the announcement">Read More</span></a>
<script>
Js(viewmodel)
var OpenNewsPopupViewModel = function() {
var self = this;
self.Title = ko.observable("");
self.Summary = ko.observable("");
self.Content = ko.observable("");
self.ImageURL = ko.observable("");
self.AddTime = ko.observable("");
self.AddDate = ko.observable("");
self.AddYear = ko.observable("");
self.SubmitedBy = ko.observable("");
self.ImageURLFull = ko.observable("");
};
var openNewsPopupViewModel = null;
function openNewsPopup(pTitle, pSummary, pContent, pImageURL, pAddTime, pAddDate, pAddYear, pSubmitedBy) {
var imageRootPath = '@Url.Content("~/Images/Announcements/NewsTypes/NewsType")';
var isNewViewModel = (openNewsPopupViewModel == null);
var newsPopup = $("#newsPopup");
if (isNewViewModel)
{
openNewsPopupViewModel = new OpenNewsPopupViewModel();
var newsPopupTag = newsPopup.get()[0];
ko.applyBindings(openNewsPopupViewModel, newsPopupTag);
}
// pContent = str.replace(/\"/g, "\\\"");
openNewsPopupViewModel.Title(pTitle);
openNewsPopupViewModel.Summary(pSummary);
openNewsPopupViewModel.Content(pContent);
openNewsPopupViewModel.ImageURL(pImageURL);
openNewsPopupViewModel.AddTime(pAddTime);
openNewsPopupViewModel.AddDate(pAddDate);
openNewsPopupViewModel.AddYear(pAddYear);
openNewsPopupViewModel.SubmitedBy(pSubmitedBy);
openNewsPopupViewModel.ImageURLFull("");
openNewsPopupViewModel.ImageURLFull(imageRootPath + '.' + openNewsPopupViewModel.ImageURL() + '.jpg');
newsPopup.modal('show');
}
Sample data(that should be replaced double quotes)
<a href="javascript:openNewsPopup(' Version 1 is Released','Version 1.0
is now available on web. You can download the new version of the
client program from the website" http:="" 255.255.255.0="" test"="" or=""
installed="" program="" can="" automatically="" download="" it="" for=""
you.','news="" context="" will="" be="" placed="" here.="" news="" .=""
','update','12:04',="" '01.01','2013','admin')"="" class="btn pull-right"><span
style="font-weight:normal" rel="tooltip" title="Read more about the
announcement">Read More</span></a>
You need to encode the strings before sending them down to the client. If setting the strings in a Razor view, you can simply call @Html.Encode(string)
. To encode the content outside of a Razor view (e.g. in your data access code) just call System.Web.HttpUtility.HtmlEncode(string)
directly.
HttpUtility.HtmlEncode("A simple 'encoded' \"string.\"");
// A simple 'encoded' "string."
这篇关于使用Javascript - 如何逃脱剑道模板双人和单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!