如果 kendo 网格中的图像字段为空,如何显示默认图像?

How to show default image if image field is null in kendo grid ?

如果图像字段是 null.This 我想显示默认图像 null.This 是我的图像字段代码。

{ field: "Photo",
title: "Photo",
template: '<img src="#= Photo #" alt="image" width="80px" height="80px" />',
width: 100
}

试试这个

{
    field: "Photo",
    title: "Photo",
    template: function(dataItem) {
        return kendo.template(
           '<img src="#= Photo #" alt="image" width="80px" height="80px" />'
        )({Photo: dataItem.Photo || 'http://path-to-image'});
    }
    width: 100
}

这个dataItem.Proto || 'http://path-to-image'表示如果Photo是假的(nullfalse0''undefined ) 然后使用默认路径

Example

简单!

{
    field: "Photo",
    title: "Photo",
    template: '<img src="#= Photo == null ? "http://exemple.com/pic.jpg" : Photo #" alt="image" width="80px" height="80px" />',
    width: 100
}