sencha touch 更改特定列表项的颜色
有一个非常基本的列表组件,但想要根据值更改某些行的行颜色/我尝试设置 tpl 但它似乎不起作用。任何帮助将不胜感激
Ext.create('Ext.dataview.List', {
id : 'mylist',
store: myStore,
tpl: new Ext.XTemplate(
'<tpl for=".">'
' <tpl if="val == 0"><div style="background-color:red">{name}</div></tpl>',
' <tpl if="val == 1"><div>{name}</div></tpl>',
'</tpl>'
)
});
have a very basic list component, but want to change the row colour of some rows depending on a value/ I have tried setting a tpl but it doesnt seem to work. Any help would be appreciated
Ext.create('Ext.dataview.List', {
id : 'mylist',
store: myStore,
tpl: new Ext.XTemplate(
'<tpl for=".">'
' <tpl if="val == 0"><div style="background-color:red">{name}</div></tpl>',
' <tpl if="val == 1"><div>{name}</div></tpl>',
'</tpl>'
)
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
啊,基本错误,这就是您在代码中得到的 ::
这才是它应该的样子 :::
** 注意您需要在两个值之间添加的三个“等于”符号实际上比较。因此,如果您通常
在模板中编写“Then”,则会出现
这样的条件语句:
Becomes
EDIT :: 为整行添加编码,以填充指定的背景颜色
注意:: 请创建一个单独的 XTemplate 对象,而不是内联 tpl代码。这将使您能够充分利用 XTemplate 的潜力,包括非常酷的成员函数!
试用 1 ::
tpl 要添加的背景颜色代码
//注意:我已在用于更改背景颜色的辅助函数中添加了班级。我的 tpl 基本上在每个列表行上使用替代颜色。因此,如果第一行是绿色,第二行是黄色,第三行是绿色,第四行是黄色,依此类推。
要添加的关联 CSS(针对 li 标签中选择的 listClasses)
编辑试用 2 :: 要添加的新 CSS
CSS
要将 CSS 添加到代码中,请添加以下内容到列表对象::
Ah, basic mistake, this is what you've got in your code ::
And this is what it should be instead :::
** Notice the three "equal to" signs that you need to add between the two values you're actually comparing. So if you normally wrote
Then in a template that would be
So a conditional statement like
Becomes
EDIT :: Adding the Coding for the entire row to be filled with the background color assigned
NOTE :: Please make a separate XTemplate object, and not inline tpl code. That will allow you to harness the full potential of the XTemplate, including member functions which are incredibly cool !
Trial 1 ::
tpl Code to be added for background color
//Note : I've added in the helper functions that I'm using to change the background color of the class. My tpl, basically uses alternate color on every list line. So if the first line is green, the second is yellow, the third is green, the fourth is yellow, and so on.
Associated CSS to be added (for the listClasses selected in the li tag)
EDIT Trial 2 :: New CSS to be added
CSS
To add the CSS into Code, add the following to the list object ::
这可能会晚,但你可以这样做
,并在你的 css 文件中添加列表样式
This may be late but you can do it this way
and in your css file just add the list style
这就是我所做的:
在我的 css 中,我使用背景渐变而不是背景颜色:
Here's what I do:
In my css instead of a background color I use a background gradient: