Answer the question
In order to leave comments, you need to log in
How to correctly pass render parameters to Backbone?
Hello!
I have the following problem:
I decided to re-architect my Backbone test in the following way.
At first, my collections were fetched directly in the View, in the render function. Heard. that it’s not good to do this, so I’m redoing it so that the collection is fetched in the router, and the data is transferred to the view.
I tried doing this:
view:
define([
'jquery',
'underscore',
'backbone',
'form2js',
"pages/test/collections/users",
"pages/test/models/user",
'text!pages/test/templates/users.html'
], function($, _, Backbone, form2js, UsersCollection, UserModel, UsersTemplate) {
var UsersView = Backbone.View.extend({
el: '#main_content',
initialize: function(users) {
this.users = users;
_.bindAll(this, 'render', this);
},
render: function() {
var that = this;
var template = _.template(UsersTemplate, {
users: users;
});
this.$el.html(template);
}
define([
"pages/test/views/usersView",
"pages/test/collections/users",
],
function(usersView, UsersCollection) {
return Backbone.Router.extend({
routes: {
"users": 'users',
},
users: function() {
users = new UsersCollection();
users.fetch();
console.log(users);
if (typeof UsersView === "undefined") {
UsersView = new usersView();
};
UsersView.render({
users: users
});
}
UsersView = new usersView();
is an error on the line in the consoleroutes.js: Uncaught TypeError: undefined is not a function
. I understand that I'm doing something wrong, but unfortunately I'm not very familiar with JS to solve the problem myself. Answer the question
In order to leave comments, you need to log in
Did you forget to return UsersView at the end of pages/test/views/usersView?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question