When I realized "check all" by jquery, some bad things happened, way.js unable to detect changes in the value of, so I can manually trigger "change" events, but "setTimeout" led to erroneous results.
My code:
<!--html-->
<input type="checkbox" data-checkAll="a1"/> Check All
<input type="checkbox" value="1" data-checkall-bind="a1" way-data="ids.1">
<input type="checkbox" value="2" data-checkall-bind="a1" way-data="ids.2">
<input type="checkbox" value="3" data-checkall-bind="a1" way-data="ids.3">
<!--javascript-->
<script>
$("input[type=checkbox][data-checkAll]").on('click',function(e){
var p = $(this).attr('data-checkAll');
var checked = $(this).prop('checked');
var items = $("input[type=checkbox][data-checkAll-bind='"+p+"']");
items.prop('checked',checked);
var evt = document.createEvent('Event');
evt.initEvent('change',true,true);
items.each(function(){
this.dispatchEvent(evt);
});
});
</script>
<!--console result-->
way.get('ids');//{3:3}
As you can see, I hope the result is "{1:1,2:2,3:3}".
Then I look at your code, found to be caused here:
var eventInputChange = function(e) {
if (timeoutInput) { clearTimeout(timeoutInput); }
timeoutInput = setTimeout(function() {
var element = w.dom(e.target).get(0);
way.dom(element).toStorage();
}, way.options.timeout);
}
Because I was using code triggered, event interval is very, very small, so "clearTimeout" is continuously invoked.
When I realized "check all" by jquery, some bad things happened, way.js unable to detect changes in the value of, so I can manually trigger "change" events, but "setTimeout" led to erroneous results. My code:
As you can see, I hope the result is "{1:1,2:2,3:3}".
Then I look at your code, found to be caused here:
Because I was using code triggered, event interval is very, very small, so "clearTimeout" is continuously invoked.
Then I changed the code,look here: https://github.com/keepeye/way.js/commit/10047f5f49447895a905847d4802cd2688fc139e
I don't know if it will bring unexpected problems,but it works for me.