Hello, everyone!
Firstly, CanJS is really awesome. Thanks for this work. I try write first realtime app and have few newbie question about events in model. I have this code:
Firstly, CanJS is really awesome. Thanks for this work. I try write first realtime app and have few newbie question about events in model. I have this code:
- $(function(){
can.Model.extend('Collection', {
findAll: 'GET /collection',
findOne: 'GET /collection/{id}',
create: 'POST /collection',
update: 'PUT /collection/{id}',
destroy: 'DELETE /collection/{id}'
}, {});
var MyControl = can.Control.extend({
init: function(element , options){
var el = this.element;
Collection.findAll({}, function(collections){
el.html(can.view('collections', { collections: collections }));
});
},
".add click": function(el, ev) {
var coll = new Collection({ name: 'N '+Math.random() });
coll.save();
},
"li click": function(el, ev) {
Collection.destroy(el.closest('li').data('coll').id);
},
"{Collection} created": function() {
console.log('created');
},
"{Collection} destroyed": function() {
console.log('destroyed');
}
});
new MyControl(".wrapper", { });
});
All model's method work fine, i can render all collections, add new and destroy, BUT, events "created" and "destroyed" didn't fire and console is empty :(
I also tried to use an example from the documentation and have same results. Model is work, events is dont.
I understand that something I do not understand
, and I will be glad if someone can help me and advise how to work with the events of the model
.