Answer the question
In order to leave comments, you need to log in
How to connect JST template to MarionetteView?
Good evening!
I compile the JST template and insert its code before the View
<div id="review_template">
<% _.each( items, function( item ){ %>
<div class='col-md-6 name-rev'>
<p class="text"><strong><%- item.clientName %></strong></p>
</div>
<div class='col-xs-12 wrap' style='margin-bottom: 15px; padding: 10px 10px 5px 10px;'>
<div class='col-md-6 time-rev'>
<p class="text"><strong><%- item.id %></strong></p>
</div>
<br>
<hr style='margin-top: 5px; margin-bottom: 5px;'>
<div class='col-md-12'>
<p class="text"></p>
</div>
</div>
<% }); %>
</div>
(function() {
window["JST"] = window["JST"] || {};
window["JST"]["reviews.jst"] = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
with (obj) {
__p += '<div id="review_template">\r\n ';
_.each( items, function( item ){ ;
__p += '\r\n <div class=\'col-md-6 name-rev\'>\r\n <p class="text"><strong>' +
__e( item.clientName ) +
'</strong></p>\r\n </div>\r\n <div class=\'col-xs-12 wrap\' style=\'margin-bottom: 15px; padding: 10px 10px 5px 10px;\'>\r\n <div class=\'col-md-6 time-rev\'>\r\n <p class="text"><strong>' +
__e( item.id ) +
'</strong></p>\r\n </div>\r\n <br>\r\n <hr style=\'margin-top: 5px; margin-bottom: 5px;\'>\r\n <div class=\'col-md-12\'>\r\n <p class="text"></p>\r\n </div>\r\n </div>\r\n ';
}); ;
__p += '\r\n</div>\r\n';
}
return __p
}})();
var ReviewsView = Marionette.View.extend({
initialize: function () {
this.collection = new app.ReviewCollection();
this.collection.fetch();
},
template: JST['reviews.jst']
});
var myView = new ReviewsView();
myView.render();
Answer the question
In order to leave comments, you need to log in
How is Marionette.Renderer written? I usually recommend writing something like:
Marionette.Renderer.render = function(template, data) {
return JST[template](data);
};
var ReviewsView = Marionette.View.extend({
initialize: function () {
this.collection = new app.ReviewCollection();
this.collection.fetch();
},
template: 'reviews.jst',
});
JST['reviews.jst']({ items: [] });
The problem was found and it is not in the template...
The collection is empty, I rewrote it on Backbone for the time being, on the weekend they will write an application, figure it out, apparently there is some kind of jamb with events... In any case, thanks for the help.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question