Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sencha touch Sencha touch itemTpl,不按条件显示行_Sencha Touch_Itemtemplate - Fatal编程技术网

Sencha touch Sencha touch itemTpl,不按条件显示行

Sencha touch Sencha touch itemTpl,不按条件显示行,sencha-touch,itemtemplate,Sencha Touch,Itemtemplate,如果值为'xxx',我不想在itemTpl中显示行 例如: itemTpl: '{title}', data: [ { title: 'Item 1' }, { title: 'Item 2' }, { title: 'Item 3' }, { title: 'Item 4' } ] 这里,如果title=='Item 2'表示我不应该显示该行。我需要跳过它 如何实现这一点?这取决于您用来显示数据的组件 如果您使用的是一个列表(并且数据存在于一个存储中),您可以

如果值为'xxx',我不想在itemTpl中显示行

例如:

itemTpl: '{title}',
data: [
    { title: 'Item 1' },
    { title: 'Item 2' },
    { title: 'Item 3' },
    { title: 'Item 4' }
]
这里,如果title=='Item 2'表示我不应该显示该行。我需要跳过它


如何实现这一点?

这取决于您用来显示数据的组件

如果您使用的是一个列表(并且数据存在于一个存储中),您可以使用它来简单地过滤列表,实际上不显示您的行


如果您正在使用另一个输出原始HTML的组件,则必须在XTemplate中为itemTpl使用条件逻辑。

在视图中,进行以下更改:

xtype: 'list',
id: 'myList',
//itemTpl: '{title}',
data: [
    { title: 'Item 1' },
    { title: 'Item 2' },
    { title: 'Item 3' },
    { title: 'Item 4' }
]
在视图的initialize()函数中写入:

var myList = Ext.getCmp('myList');
myList.setItemTpl([
      '<tpl if="title!=\'Item 2\'">',
      '{title}',
      '<tpl else>',
      '',
      '</tpl>'
]);
var myList=Ext.getCmp('myList');
myList.setItemTpl([
'',
“{title}”,
'',
'',
''
]);
我想,这应该对你有用