如何将 dataview itemTpl 绑定到 viewModel?

问题描述

我想将数据视图项目标记为收藏。如何按照逻辑将 dataview itemTpl 类绑定到 viewmodel:

<i class="   '{isFavorite?"class1":"class2"}'    "></i>

其中 isFavorite 是模型字段类型布尔值。

itemTpl 类似于

itemTpl: new Ext.XTemplate(
  '<div class="card" style="padding-left: 32px;">','<div class="img"><img src="{src}" class="imgClass"></div>','<div><img class="favorite-yes"></div>','</div>',)   

css

.favorite-yes {
    width: 24px;
    height: 24px;
    background: url(http://pngimg.com/uploads/heart/heart_PNG51337.png) no-repeat;
}

.favorite-no {
    width: 24px;
    height: 24px;
    background: url(http://www.pngall.com/wp-content/uploads/3/Heart-Background-PNG-Image.png) no-repeat;
}

解决方法

试试

itemTpl: new Ext.XTemplate(
  '<div class="card" style="padding-left: 32px;">','<div class="img"><img src="{src}" class="imgClass"></div>','<div>','<tpl if="isFavorite">','   <img class="favorite-yes">','<tpl else>','   <img class="favorite-no">','</tpl>','</div>',)  

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...