简体   繁体   English

你如何强迫Ember重新渲染一个组件?

[英]How do you force Ember to rerender a component?

I have an Ember component that uses jQuery to add a canvas chart. 我有一个使用jQuery添加画布图的Ember组件。 When I change routes, I get a new model, but Ember's automatic rerendering does not work in this case. 当我改变路线时,我得到了一个新模型,但在这种情况下,Ember的自动重新渲染不起作用。 In fact, I don't know how to make the component code which adds the chart re-run at all. 事实上,我不知道如何制作添加图表的组件代码。 How can I do this? 我怎样才能做到这一点?

Would it work better if it was a view? 如果它是一种观点,它会更好吗?

Without looking at code, I'm going to guess based on your statement of the model changing. 在不查看代码的情况下,我将根据您对模型更改的陈述进行猜测。

Component Currently 组件目前

uiSetup: function(){
   // do magic here...
}.on('didInsertElement')

Component with observes 观察组件

Assuming the model in the component is named model, this would fire every time the model changed as well as when the element was initially inserted into the page. 假设组件中的模型名为model,则每次模型更改时以及元素最初插入页面时都会触发。 You could also break it into two separate functions if you need it to act differently on model change vs element inserted first time. 如果您需要在模型更改与第一次插入的元素上采取不同的行动,您也可以将其分解为两个单独的函数。

uiSetup: function(){
   // do magic here...
}.on('didInsertElement').observes('model') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM