2012-12-09 41 views
2

我知道如何更新和重绘jqPlot对象不使用烬 ...如何使用ember.js更新jqPlot图形?

我创建了下面的小提琴表现出“问题”:http://jsfiddle.net/QNGWU/

这里,函数的App.graphStateControllerload()被称为每秒钟更新控制器内容中的系列数据。

第一个问题:系列的更新似乎没有传播到视图。

第二个问题:即使他们愿意,我可以在哪里拨打电话来更新地图(即plotObj.drawSeries())?

我已经尝试过登记在视图的didInsertElement功能的观察者:

didInsertElement : function() { 
    var me = this; 
    me._super(); 
    me.plotObj = $.jqplot('theegraph', this.series, this.options); 
    me.plotObj.draw(); 
    me.addObserver('series', me.seriesChanged);  
}, 
seriesChanged: function() { 
    var me = this; 
    if (me.plotObj != null) { 
    me.plotObj.drawSeries({}); 
    } 
} 

但没有奏效...

回答

1

嘛,搞明白了,看updated fiddle

的秘诀是更新App.graphStateController整个graphState对象(不只是它的属性):

var newState = App.GraphState.create(); 
newState.set('series', series); 
me.set('content', newState); 

,然后附加的观测者在App.graphStateView

updateGraph : function() { 
    [...] 
}.observes('graphState') 

updateGraph函数然后并不漂亮,因为jqPlot的数据系列存储为[x,y]对。

整个问题,我想,是在本身不从Ember.object而来,因此没有事件对他们打响了App.graphState对象的属性seriesoptions。另一种解决方案也可能是将其更改为Ember.objects