2015-11-11 35 views
0

为了造型的目的,我需要一个类有一个变量的值作为类名添加变量值类战车触摸

config: { 
    cls: 'section cart-item {variable}', 
    items: [{ 
     layout: 'hbox', 
     items: [{ 
      name: 'image', 
      cls: 'left', 
      flex: 4, 
      tpl: [ 
       '<div style="min-height: 10em"><img src="{thumbnail}" width=100 /></div> 
      ].join('') 
     } 
... 

这似乎不是工作的一部分。我读过不支持向cls添加变量。

有太多的事情要下尝试使用第三方物流的方式。有没有办法打破一切,或添加一个ID或别的东西?

+0

可以添加类,而这一观点正在初始化或油漆事件,假设视图的ID是'someView'比'Ext.getCmp( 'someView')addCls(varibleCls);'。 –

+0

但是可以“variableCls”像'{变量}'的可变的结果? – spasticninja

+0

请检查答案。 –

回答

1

假设你有一个观点,你想动态分配类,这里是这样的

Ext.define('someview.namespace',{ 
    config: { 
     cls: 'section cart-item', 
     // here all other code 
    }, 
    initialize: function(){ 
     this.callParent(); 
     var cls = 'abc'; // here get your class dynamically. 
     this.addCls(cls); 
    } 
}); 
+0

完美。谢谢! – spasticninja