2014-04-22 37 views
1

所以在后端我使用PHP和这里是如何字符串格式化:剑道HTML字符串得到HTML格式ヶ辆

$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" } 
      } 
     }   
    } 
});  

我得到的文本显示为结果。当我试图检查我得到这个文本

&lt;img src='url/test1.jpg'&gt;&lt;img src='url/test2.png'&gt; 

而我不知道它发生了什么女巫点,为什么。

我正在使用最新版本的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

'html_entity_decode'是怎么回事。 – Ohgodwhy

+0

我实际上正在使用它来试图阻止它。 [文档](http://www.php.net/manual/en/function.html-entity-decode.php) –

+1

向我们展示如何使用照片字段。 –

回答

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/

+0

非常有帮助。我想强调'#=照片#'(等号),而不是'#:照片#'(冒号)。这些行为类似于打开asp.net标记<%= vs. <%:因为equals不会自动进行编码。冒号。大多数kendo演示使用冒号。 – nickles80