cssextjsdataview

How to bind dataview itemTpl to viewModel?


I would like to mark dataview item as favorite. How can I bind dataview itemTpl class to viewModel following the logic:

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

where isFavorite is model field type boolean.

itemTpl is something like

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;
}

Solution

  • Try

    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>',               
      '</div>',
    )