添加新 attributeModifier 时如何删除先前的 attributeModifier?
我有两列,它们是 orderbyborder 链接。当我单击一列时,我通过按以下方式添加 attributeModifier 更改了列的颜色
add(new AttributeModifier("style", true, new Model<String>("background-color:#80b6ed;")));
这工作正常。但是当我单击第二列时,第一列保持更改后的颜色。但我希望只有我单击的列才应包含此 attributeModifier!
I have two columns which are orderbyborder links. When i click one column i changed the color of column by adding attributeModifier in the following way
add(new AttributeModifier("style", true, new Model<String>("background-color:#80b6ed;")));
This works fine. But when i click on second column, the first column remains the changed color. But I expect only the column which i click should hold this attributeModifier!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该更改修饰符。
诀窍是让你的模型返回正确的值。因此,您不必使用始终返回相同常量值的
new Model("background-color:#80b6ed;")
,而是使用以下内容:当然,这也意味着您可以在创建每一列时为其添加属性修饰符,并且以后不必担心它们。
You shouldn't change the modifier.
The trick is to have your model return the correct value. So instead of using
new Model<String>("background-color:#80b6ed;")
, which always returns the same constant value, you'd have something like:And of course this also means you can add an attribute modifier to every column when you create them and don't have to worry about them later on.
实现您想要的效果的另一种方法是通过 Javascript 将 css 类添加到所选行(从旧类中删除该类)。
Another way to achieve what you want is to add a css class to the selected line via Javascript (removing the class from old one).