所以在后端我使用PHP,这里是字符串格式化的方式:
$temp['photos'] = html_entity_decode( $HTMLformatedImg );
并且作为回应它的格式正确:
"photos":"<img src='url/test1.jpg'><img src='url/test2.png'>"
当我尝试使用以下方式将其显示给用户时:
dataSourceDeals = new kendo.data.DataSource({
//serverPaging: true,
serverSorting: true,
transport: {
read: {
url: crudServiceBaseUrlDeals + "read&businessId={/literal}{$details.id}{literal}",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrlDeals + "update&businessId={/literal}{$details.id}{literal}",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrlDeals + "destroy&businessId={/literal}{$details.id}{literal}",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrlDeals + "create&businessId={/literal}{$details.id}{literal}",
dataType: "jsonp"
},
},
batch: false,
pageSize: 10,
schema: {
total: "total",
data: "data",
model: {
id: 'id',
fields: {
id: { type: "number", editable: false },
dealName: { type: "string" },
photos: { type: "string" },
description: { type: "string" },
active: { type: "string" }
}
}
}
});
我显示了文字结果。当我试着检查那个文本时,我得到了这个
<img src='url/test1.jpg'><img src='url/test2.png'>
我不确定发生了什么事以及为什么。
我正在使用最新版本的Kendo UI。
修改
$("#deals").kendoGrid({
dataSource: dataSourceDeals,
pageable: true,
resizable: true,
toolbar: [{ text:"Add Deal", className: "gridAddDeal"}, { text:"Edit Selected", className: "gridEditDeal"}, { text:"Delete Selected", className: "gridDeleteDeal"}],
height: 400,
sortable: 'true',
selectable: true,
columns: [
{ field: "id", title: "ID", width: "40px" },
{ field: "dealName", title: "Coupon Name", width: "100px" },
{ field: "photos", title: "Photos", width: "100px" },
{ field: "description", title: "Description", width: "100px" },
{ field: "active", title: "Active", width: "70px" }
]
});
答案 0 :(得分:3)
不确定它是否是缺陷或功能,但您可以轻松解决它将photos
字段的模板定义为template: "#= photos #"
:
columns: [
{ field: "id", title: "ID", width: "40px" },
{ field: "dealName", title: "Coupon Name", width: "100px" },
{ field: "photos", title: "Photos", width: "100px", template: "#= photos #" },
{ field: "description", title: "Description", width: "100px" },
{ field: "active", title: "Active", width: "70px" }
]
请在此处查看:http://jsfiddle.net/OnaBai/H6dD5/
从我的观点来看,这是一项功能,因为这是能够将特殊字符打印为<
,>
,&
...而无需模板的唯一方法。据了解,您可能不会发送HTML,而是会生成一些可生成HTML的可变数据。
或者,您可以考虑将照片的网址发送为逗号分隔值photos: 'url/test1.jpg, url/test2.png'
,然后将模板定义为:
<script id="photo-tpl" type="text/kendo-tpl">
# var ps = data.photos.split(","); #
# for (var i = 0; i < ps.length; i++) { #
<img src="#= ps[i] #"/>
#}#
</script>
不确定这是否比在后端生成HTML更容易,但至少它(从我的角度来看)更清晰地分离了模型 - 视图 - 控制器。
请在此处查看此方法:http://jsfiddle.net/OnaBai/H6dD5/1/