javascript - 如果图像字段在剑道网格中为空,如何显示默认图像?

标签 javascript jquery kendo-ui kendo-grid

如果图像字段为空,我想显示默认图像。这是我的图像字段代码。

{ 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 是假的(null, false, 0 , '', undefined) 然后使用默认路径

Example

关于javascript - 如果图像字段在剑道网格中为空,如何显示默认图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28455592/

相关文章:

javascript - 将鼠标悬停在图像上可添加效果,再次悬停可使其消失

javascript - Xamarin Android Webview Javascript

javascript - 如何阻止div接受点击事件

克隆后的 jQuery 冲突

jquery - slider 点 - css3 使它们沿对 Angular 线倾斜

templates - 如何获取从剑​​道模板创建的剑道网​​格弹出添加/编辑表单,显示添加和编辑操作的正确标题?

javascript - 这个递归函数有什么问题?

javascript - 使用 javascript 执行计算的两个八进制数

javascript - 如何通过 JavaScript 创建 Telerik MVC 组合框

javascript - KendoUI ComboBox 显示 REST JSON 的错误解析