首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExtJS :在分组组合框tpl中动态传递组名

ExtJS :在分组组合框tpl中动态传递组名
EN

Stack Overflow用户
提问于 2019-05-30 13:49:01
回答 1查看 387关注 0票数 0

我正在处理一个组组合框,在这里我需要动态地传递组名(从它的配置)。

代码语言:javascript
复制
  var data = [{
           group: 'Fubar',
           key: '1',
           name: '2015 Product Development'
       }, {
           group: 'Fubar',
           key: '2',
           name: 'Message Filter'
       }, {
           group: 'Fubar',
           key: '3',
           name: '2014 Product Development (Little)'
       }, {
           group: 'Other',
           key: '4',
           name: 'Global Structure'
       }, {
           group: 'Other',
           key: '5',
           name: 'My SW'
       }];
    Ext.apply(combo, {
            listConfig: {
        tpl = new Ext.create('Ext.XTemplate',
               '<tpl for=".">',
               '<tpl for="group" if="this.shouldShowHeader(group)"><div class="group-header">{[this.showHeader(values.group)]}</div></tpl>',
               '<div class="x-boundlist-item"><input type="checkbox" />{name}</div>',
               '</tpl>', {
                   shouldShowHeader: function(group) {
                       return this.currentGroup !== group;
                   },
                   showHeader: function(group) {
                       this.currentGroup = group;
                       return group;
                   }
               });
}
});
var combo = Ext.create('Ext.data.Store', {
       fields: ['group', 'key', 'name'],
       data: data
   });
 items: [{
           xtype: 'combobox',
           id: 'searchInput',
           store: combo,
           multiSelect: true,
           labelWidth: 50,
           queryMode: 'local',
           displayField: 'name',
           fieldLabel: 'Choose',
           listConfig: {
               cls: 'grouped-list'
           },
           tpl: tpl,
groupName: 'group'
}]

我试过使用代码,但不起作用。它给了group,属性本身而不是它的价值。

代码语言:javascript
复制
<tpl for="combo.groupName" if="this.shouldShowHeader(combo.groupName)">
  • 这里,组合体是正在使用的combobox实例。
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-03 11:46:30

应该以这种方式使用Tpl来获得所需的输出。

代码语言:javascript
复制
  '<tpl for=".">',
    '<tpl for="' + combo.groupName + '" if="this.shouldShowHeader(' + combo.groupName + ')"><div class="group-header">{[this.showHeader(values.' + combo.groupName + ')]}</div></tpl>',
    '<div class="x-boundlist-item"><input type="checkbox" />{name}</div>',
  '</tpl>'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56379609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档