Answer the question
In order to leave comments, you need to log in
What is the correct way to call the constructor function inside render in Backbone?
Good evening. I can't solve the puzzle at all...
I need to create a chart using backbone.js and any library (I use chart.js)
html code ...
-div class="container"-
-canvas id="myChart" width="100" height="100"--/canvas-
-/div-
...(removed brackets because they don't show block)
js code ...
var ChartView = Backbone.View.extend({
className: "chart",
initialize: function () {
this.render();
},
render: function () {
var ctx = $('#myChart'); //canvas element is accessible
var data = this.model.get("data" ); //data access is
var options = this.model.get("
this.$el.html( new Chart(ctx, {data, options}) ); // error here( I tried a bunch of different options.. but I don't know what to do anymore....
}
});
varchart = new NewChart;
var chartView = new ChartView({model: chart});
...
error:
Chart.js:4210 Uncaught TypeError: Chart.controllers[meta.type] is not a constructor(…)
Answer the question
In order to leave comments, you need to log in
The man himself is an arkestre))
I am writing an answer, you never know who will come in handy.
The whole point was that I incorrectly passed data to the table creation function...
Correctly so -
render: function () {
var ctx = $('#myChart');
this.$el.html( new Chart(ctx, this.model.toJSON()) );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question