我使用radialProgress作为jQuery插件(自制),我需要为ember实现它,但我有一些问题要做。
插件的快速说明:
var chart = $(yourElement).pieChart(options); // initialise the object to an element
chart.setCompleteProgress( complete, false ); // set how many item you have to complete the task
chart.incrementProgress(); // increment + 1 every time you call it
这是一个非常简单的进步派。
在我的情况下,我的任务位于我的控制器内,但是图表选择了一个dom元素,所以我需要在我的视图中初始化它。 我在控制器中的任务是从setupController从路由器调用的,以便随着时间的推移重新加载模型。
以下是我想做的一小部分示例:
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller) {
var promise = controller.getModel();
this._super(controller, promise);
}
})
App.ApplicationController = Ember.ArrayController.extend({
getModel: function() {
// chart.setcompleteProgress();
// A lot of code are here to get some data
// chart.incrementProgress();
return newModel;
}
})
App.ApplicationView = Ember.View.extend({
didInsertElement: function() {
var chart = $(element).pieChart(opts);
}
})
我不知道如何将图表对象从视图传递到控制器,以便能够访问我的插件功能。
答案 0 :(得分:1)
在didInsertElement
之前,Che图表不会插入到DOM中,因此您无法在route
期间尝试在setupController
中操作它。我&# 39;建议在控制器setupChart
中创建一个方法,并在didInsertElement
上调用该方法。
App.ApplicationView = Ember.View.extend({
prepPieChart: function() {
var chart = $(element).pieChart(opts);
this.get('controller').setupPieChart(chart);
}.on('didInsertElement')
})
App.ApplicationController = Ember.ArrayController.extend({
setupPieChart: function(chart) {
chart.setcompleteProgress();
// A lot of code are here to get some data
chart.incrementProgress();
}
})
所有这一切,也许它属于视图,但我不确定你完全在做什么。