如果图像字段为空,我想显示默认图像。这是我的图像字段代码。
{ 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
) 然后使用默认路径
关于javascript - 如果图像字段在剑道网格中为空,如何显示默认图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28455592/