Tuesday 15 April 2014

javascript - How can I select an element from inside a Marionette event handler? -



javascript - How can I select an element from inside a Marionette event handler? -

edit: added more code

i'm listening event on model this: (this view)

var view = marionette.itemview.extend({ tagname: 'tr', template: viewtemplate, modelevents: { "change:highscore": "highchange" }, highchange: function (model) { var elem = this.$('.send'); console.log(elem); elem.hide(); this.render(); } });

and template:

<td class="cusername">{{username}}</td> <td class="highscore"> <div class="box"> <button class="send"></button> <span>send</span> </button> </div>

(this within marionette.itemview.extend({...}); ) when model changes highscore want send element hidden when above nil changes. console.log(elem) gives me element object[div.send] right element, doesn't hidden.

does have lifecycle of marionette? how can alter element hidden result of event on model?

do have more 1 element 'send' class within view context? if so, may need disambiguate relative target element. if understand relationship between target of event , element want manipulate, can access way:

highchange: function (e) { var elem = $(e.target).find('.send'); // if .send kid element var elem = $(e.target).closest('.send'); // if .send parent element }

javascript html dom backbone.js marionette

No comments:

Post a Comment