如何在Ember Table中应用“Blink”功能? [英] How to apply 'Blink' feature in Ember Table?
问题描述
在 setTimeout
中应用颜色和删除颜色时,我调用了 setTimeout
。它不工作所有的时间。某些单元格颜色不会被删除。
(滚动时会变得更糟)。我假设1秒钟后,Ember找不到特定的单元格元素。
我使用和Ember表组件并分配了一个 contentBinding
和 columnBinding
。我为 Ember.Table.TableCell
组件添加了一个模板,并添加了类名。
我不能保证这会回答你的问题,但是在阅读这段代码的时候,这里有一堆东西跳出来。我认为他们最好被格式化为答案。
-
你应该避免副作用,比如调用
setTimeout
,在计算的属性内。 Ember中的计算属性是懒惰的,所以只有当需要它们的值时才更新它们。在这种情况下,请考虑使用Observer
或只是一个函数。这几乎肯定与你的问题有关。 -
而不是
setTimeout
,使用Ember.run.later
或类似的Ember功能。这将确保您的代码遵循Ember运行循环。 -
您的
customColor
计算属性不取决于previousColumnValue
,即使它使用它。这与副作用讨论有关:如果可能,您应该尝试重新构建您的代码。
其他比那个,你有很多正确的想法。我相当肯定这可以通过Ember Table完成 - AJAX示例是处理异步的Ember Table单元格的一个例子。
我建议调试首先尝试在JS Bin中创建一个最小的例子,使用 Ember Table入门套件。如果您希望获得更多帮助,这样做也将非常有用 - 这样可以让我像我这样的人玩,直到它运行。
in Ember Table, I need to change style of a cell with the change of particular cell content. I need to add color to cell with value update (that I have already done) and remove styles after 1 second (that I want to do).
I have called setTimeout
when applying color and removed color within setTimeout
. It does not work all the time. some cell colors are not removed.
(this gets worse when scrolling). I assume after 1 second, Ember cannot find the particular cell element.
I use and Ember table component and assigned a contentBinding
and columnBinding
. I added a template for the Ember.Table.TableCell
component and added class names.
I can't guarantee that this will answer your question, but here are a bunch of things that jump out at me when reading this code. I think they are best formatted as an "answer".
You should avoid side-effects, like calling
setTimeout
, within a computed property. Computed properties in Ember are lazy, so they only update when their value is needed. Consider using anObserver
, or just a function, in cases like this. This is almost certainly related to your problem.Instead of
setTimeout
, useEmber.run.later
or similar Ember functions. This will make sure your code respects the Ember run loop.Your
customColor
computed property doesn't depend onpreviousColumnValue
, even though it uses it. This is related to the side-effects discussion: you should try to re-architect your code if possible.
Other than that, you have a lot of the right ideas. I'm fairly sure this can be done with Ember Table - the AJAX example is an example of Ember Table cells dealing with asynchrony.
I recommend debugging by first trying to create a minimal example in JS Bin, using the Ember Table starter kit. This will also be useful if you'd like more help - it makes it easy for people like me to play with your setup until it works.
这篇关于如何在Ember Table中应用“Blink”功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!