Answer the question
In order to leave comments, you need to log in
What is the correct way to use text/template to create multiple backbone.js charts?
already brainwashed.
1. created template inside html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>backbone</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<script type="text/template" id="template">
<canvas id="myChart" width="400" height="400"></canvas>
</script>
<div class="container">
<canvas id="myChart1"></canvas>
</div>
<script type="text/javascript" src="javascripts/lib/Chart.js"></script>
<script type="text/javascript" src="javascripts/lib/jquery-3.1.1.js"></script>
<script type="text/javascript" src="javascripts/lib/underscore.js"></script>
<script type="text/javascript" src="javascripts/lib/backbone.js"></script>
<script type="text/javascript" src="javascripts/chart.js" async></script>
</body>
</html>
var NewChart = Backbone.Model.extend({
defaults: {
type: 'bar',
data: {
labels: ["1", "2"],
datasets: [{
label: 'Default label',
data: [1, 2],
backgroundColor: [
'rgba(255, 99, 132, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
}
});
var ChartView = Backbone.View.extend({
tagName: "canvas",
className: "chart",
template: _.template( $("#template").html() ), // <----------------и возможно тут
initialize: function () {
this.render();
},
render: function () {
var ctx = $(myChart) // <----------------Проблема тут
//var ctx = this.$el.html(this.template()); // <----------------Проблема тут
//var ctx = $("script[type='text/template']").html(); // <----------------Проблема тут
console.log($(myChart1)); // <----------------Проблема тут
this.$el.html( new Chart(ctx, this.model.toJSON()) ); // <----------------Проблема тут
return this;
}
});
var chart = new NewChart;
var chartView = new ChartView({model: chart});
$('.container').append(chartView1.render().el);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question