Why backbone view fires change event twice?
I have backbone view as :
var aView = Backbone.view.extend({
events: {
'change #select-opr': 'changeOperation'
},
initialize: function () {},
render: function () {},
changeOperation: function () {
console.log("event triggered.");
}
});
the change event is associated with a select dropdown.
<select name="operation" id="select-opr" style="height: 29px;">
<option>Select an Attribute</option>
<option value="method">Method</option>
<option value="project">Project</option>
</select>
When i change the select options, i get two logs with 'event triggered'
in console.log. Means the event get triggered twice. Why is this so?
Have anyone found this problem before? What error i am making??
This is a common Bug in Javascript. you can find many articles around internet specially on SO for event being fired twice. I am not fan of Backbone but in jquery you can try something like this
$(document).on('click', '#task-list li', function(e)
{
alert('Hellow world');
e.stopPropagation();
return false;
});
And it's definitely Javascript problem because if you hit google and search for event fire twice you will see that Angular, Jquery and backbone etc all are somewhere firing events twice or even thrice. So, it's seems that it's javascript behind this. And off course if you search this with Mozilla Developers Network then you can see experts have also said so.
我不确定你想要实现什么,但是应该将changeOperation
绑定到选择的选项而不是选择?
上一篇: 差异iphone safari webkit vs mac safari
下一篇: 为什么骨干视图触发两次更改事件?