我正在开发angularjs页面。我有以下代码。
columnDefs: [{field:'dt', displayName:'Date', width:'***', cellFilter:'date:\"dd-MMM-yyyy\"'},
{field:'dt', displayName:'Time', width:'***', cellFilter:'date:\"HH:mm:ss\"'},
{field:'rl', displayName:'Importance',width:'80px'},
{field:'ev', displayName:'Event', width:'******'},
{field:'act', displayName:'Ac',width:'**'},
{field:'fct', displayName:'Fc',width:'**'},
{field:'fl', sortable:true, displayName:'Country',
cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text><img class="flag" src="c:/Country_Images/1.jpg}"</img></span></div>',
width: '80px'},
{field:'pre', displayName:'Pv',width:'**'}
]
我想根据 rl 的值,从项目目录“C:/ CountryImages”中显示图像(字段:fl)。 r1的值限于“H”“L”和“M”。所以,如果 rl =“H”的值那么它应该获取 C:/CountryImages/1.jpg ,如果 rl =“L”然后获取 C:/CountryImages/3.jpg
提前致谢:)
答案 0 :(得分:1)
创建一个过滤器,用于执行从rl
值到图像路径的映射,并将其应用于img ng-src
绑定表达式,例如
{field:'fl', sortable:true, displayName:'Country',
cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text><img class="flag" ng-src="row.getProperty(\'rl\') | imagefilter"</img></span></div>',
width: '80px'},
过滤器看起来像
angular.module('myApp')
.filter('imagefilter', function() {
return function(rl) {
if(rl==='L') return 'C:/CountryImages/3.jpg'
//other mappings
}
}