如何在Kendo网格中,如果图像字段为空,则显示默认图像?

3
如果图像字段为空,我希望显示默认图像。这是我的图像字段代码。
{ field: "Photo",
title: "Photo",
template: '<img src="#= Photo #" alt="image" width="80px" height="80px" />',
width: 100
}
2个回答

2

试试这个

{
    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为假值(null, false, 0, '', undefined)则使用默认路径。

示例


抱歉回复晚了。它已经成功了 :) @Alexander - Ironman

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

使用Kendo ListView for PHP是否可以实现这个功能?因为我已经设置了默认图片,但是它没有起作用。 - Amit Chaudhari

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接