var Router = Backbone.Router.extend({
routes: {
"": "index",
"admin": "admin",
"cooker": "cooker",
"waiter": "waiter"
}
});
var router = new Router;
var UsersCollection = Backbone.Collection.extend({
url: '/users/all'
});
var DishesCollection = Backbone.Collection.extend({
url: '/dishes/all'
});
var CategoriesCollection = Backbone.Collection.extend({
url: '/categories/all'
});
var LoginView = Backbone.View.extend({
model: LoginModel,
events: {
'click #trylog': 'log'
},
el: '#content',
render: function() {
var that = this;
var template = _.template($('#loginpage').html());
that.$el.html(template);
//router.navigate('admin', true);
var test = new UsersCollection();
test.fetch({
success: function(data) {
console.log(data);
}
});
}
});
var AdminView = Backbone.View.extend({
el: "#content",
render: function() {
var that = this;
var template = _.template($('#adminpage').html());
that.$el.html(template);
var test = new UsersCollection();
test.fetch({
success: function(data) {
console.log(data);
//var template = _.template($('#users_table').html(), {
// test: test.toJSON()
//});
//that.$el.html(template);
}
});
/*this.model = new UsersCollection();
this.model.on("change", this.render, this);
this.model.fetch();
this.model.parse();
var usersCollection = new UsersCollection();
usersCollection.fetch({
success: function(users) {
var template = _.template($('#users_table').html(), {
users: usersCollection.toArray()
});
that.$el.html(template);
}
});*/
}
});
var CookerView = Backbone.View.extend({
el: '#content',
render: function() {
var that = this;
var template = _.template($('#cookerpage').html());
that.$el.html(template);
var dishes = new DishesCollection();
dishes.fetch({
success: function(data) {
console.log(data);
}
});
var categories = new CategoriesCollection();
categories.fetch({
success: function(data) {
console.log(data);
}
});
}
});
var WaiterView = Backbone.View.extend({
el: '#content',
render: function() {
var that = this;
var template = _.template($('#waiterpage').html());
that.$el.html(template);
}
});
var loginView = new LoginView();
var adminView = new AdminView();
var cookerView = new CookerView();
var waiterView = new WaiterView();
router.on("route:index", function() {
loginView.render();
});
router.on("route:admin", function() {
adminView.render();
});
router.on('route:cooker', function() {
cookerView.render();
});
router.on('route:waiter', function() {
waiterView.render();
});
Backbone.history.start();
var Router = Backbone.Router.extend({
routes: {
"": "index",
"admin": "admin"
}
});
var router = new Router;
var UsersCollection = Backbone.Collection.extend({
url: '/users/all'
});
var AdminView = Backbone.View.extend({
el: "#content",
render: function() {
var that = this;
var template = _.template($('#adminpage').html());
that.$el.html(template);
var test = new UsersCollection();
test.fetch({
success: function(data) {
console.log(data);
var template = _.template($('#users_table').html(), {
test: test.toJSON()
});
that.$el.html(template);
}
});
Backbone.Collection.toJSON()
TypeError: Object function (t,e){e||(e={});if(e.model)this.model=e.model;if(e.comparator!==void 0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,i.extend({silent:true},e))} has no method 'toJSON'
Да я после backend проектов слабо понимаю зачем мне колекции и модели и в чем разница :)
Официальная документация не радует информативностью...