I don’t know about you guys, but I’ve been sorely missing being able to hook into an event from my template like in angular
//template
<button ng-click='{{doSomething(this)}}'/>
//js
function doSomething(context) {
var stuff = context.stuff; // <-- got it
}
With blaze, we have to do this:
//template
<button id='uniqueElem' data-id='...' />
//js
'click #uniqueElem': function (e, t) {
e.preventDefault();
var id = $(e.target).data('parameters');
var stuff = db.collection.findOne(id); // <-- got it
}
Secretly, I think this is why everyone is moving to react.
But I found a package that is moving in the right direction:
which allows me to do this:
//template
<button onclick="{{doSomething}}" data-id='...'>
//js
'doSomething': function (e,t) {
var id = $(e.target).data('parameters');
var stuff = db.collection.findOne(id); // <-- got it
}
// and hopefully soon, this
//template
<button onclick="{{doSomething id}}">
//js
'doSomething': function (e,t, id) {
var stuff = db.collection.findOne(id); // <-- got it
}
Does anyone get as excited as I do when reading the above? How do you guys do it?
Give.