Here is the code:
this.listen.Τo('reset', this.addAll);
this.listen.Τo('add', this.addOne);
this.listen.Τo('change', this.change);
this.listen.Τo('destroy', this.destroy);
I am just trying to make some callback to "fire" when some backbone events are initiated.
In the console I get the following message:
Uncaught TypeError: Cannot read property 'Τo' of undefined
I can post more code if that is necessary...but I think the code above is enough to draw conclusions...hopefully.
Look at you code closely. You've written listen.To( instead of listenTo.
Look again at the code. You need to specify which object you want to listen to.
I changed the code to this:
this.listenΤo('reset', this.addAll);
this.listenΤo('add', this.addOne);
this.listenΤo('change', this.change);
this.listenΤo('destroy', this.destroy);
And about which object to listenTo...where listenTo goes I hadcollection.bind.
I had tried the same code in the past and it worked...I do not know why it does not work now
I thought that it was just a simple substitution
Yes you are right...
Ι have tried several code variations to solve the problem but I cannot.
I tried this:
this.listenΤo(this.model,' reset',this.addAll);...etc
I tried assigning the collection to a variable,an idea I got from here-neither this works:
var model = new Event;//this assigment takes place outside of the view where listenTo method is located
this.listenΤo(model,'reset',th is.addAll);...etc
In any case I get undefined is not a function.
You can see a jsbin here...in lines 24-27 you will find the listenTo methods and at line 3 you will find the model declaration.
I do not know what to try next.
Several issues I see from looking at it:
* You shouldn't need to use _.bindAll(), as listenTo() takes care of setting "this" properly
* EventsView's initialize function is trying to reference "this.model", but down at the bottom, you're passing in "{ collection : events"} instead, so "this.model" isn't going to exist
* You've got a couple places where you're trying to call what look like jQuery functions on the bare element reference (ie, "this.el.fullCalendar()" should be "this.$el.fullCalendar()"
* Not entirely sure that when JSBin runs its JS code, but there's a chance that the DOM might not be ready at the time you create the EventsView instance, in which case the jQuery object you're passing in would not point to an actual element.
But the REAL issue? You've got "listenTo" entered incorrectly. That's not a Latin alphabet 'T', that's a Unicode "GREEK CAPITAL LETTER TAU", and there's certainly no Backbone functions with that letter in the name.
So, make sure that all your JS keywords and library function calls are Latin text and not Greek. :)
* You shouldn't need to use _.bindAll(), as listenTo() takes care of setting "this" properly
* EventsView's initialize function is trying to reference "this.model", but down at the bottom, you're passing in "{ collection : events"} instead, so "this.model" isn't going to exist
* You've got a couple places where you're trying to call what look like jQuery functions on the bare element reference (ie, "this.el.fullCalendar()" should be "this.$el.fullCalendar()"
* Not entirely sure that when JSBin runs its JS code, but there's a chance that the DOM might not be ready at the time you create the EventsView instance, in which case the jQuery object you're passing in would not point to an actual element.
But the REAL issue? You've got "listenTo" entered incorrectly. That's not a Latin alphabet 'T', that's a Unicode "GREEK CAPITAL LETTER TAU", and there's certainly no Backbone functions with that letter in the name.
So, make sure that all your JS keywords and library function calls are Latin text and not Greek. :)
I cannot thank you enough...it is OK now.
Two things were needed...
- Changing T to a Latin one(by the way...how did you find that the T in listenTo is Greek.)
- instead of using this.model as an argument I usedthis.collection
Heh. Found it through VERY careful trial-and-error. Added some console.log() calls to your JSBin sample, kept running it, and it always died on the first .listenTo() call. If I commented out that first call, it would die on the next one. Finally got annoyed, commented out the first line, re-wrote it myself, and saw that the line worked. Threw your line of code and my seemingly-identical line into a diff tool, and sure enough, the 'T' was different. A Unicode character lookup tool then confirmed that your line was using a Greek 'T'.
Hope that helps, and good luck!
Hope that helps, and good luck!
댓글 없음:
댓글 쓰기