我刚刚获得了 meteor 的 noUiSlider,但在监听事件时遇到了问题。这是我的代码:
Template.templateOne.events({
'click #slider': function(){
console.log('event works!');
}
});
不幸的是,这不起作用。根据this还有幻灯片等内置事件。我如何在 Meteor 中使用它们?
提前致谢!
最佳答案
必须这样绑定(bind)吗...??
Template.templateOne.events({
'click #slider': function(){
console.log('event works!');
}
});
我认为你可以这样做:
var noui = document.getElementById('#slider');
noui.noUiSlider.on('slide', function(){
console.log('i think it will work');
});
好的,然后这样做
Template.templateOne.rendered = function () {
var slider = document.getElementById('#slider')
this.slider.noUiSlider({
start: Session.get("slider"),
connect: true,
range: {
'min': 0,
'max': 100
}
}).on('slide', function (ev, val) {
console.log('i think it will work');
Session.set('slider', val);
}).on('change', function (ev, val) {
// round off values on 'change' event
Session.set('slider', [Math.round(val[0]), Math.round(val[1])]);
});
};
你可以看看这个例子https://github.com/rcy/meteor-nouislider/blob/master/example/example.js
关于javascript - meteor & noUiSlider : how can I listen to events?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42596272/