我有一个用于按键的自定义活页夹。当我调用绑定属性时,它不接受我的事件参数。就我而言,我的属性是一个我想用我自己的事件参数触发的函数。这样的事情可能吗?在下面的示例中,值是未定义的,但我如何将值传递回调用者(viewModel.onKeyPress
)?
<div id="body">
<input data-role="combobox" data-bind="keyPress: onKeyPress" />
<div id="output"></div>
</div>
<script>
kendo.data.binders.widget.keyPress = kendo.data.Binder.extend({
init: function (element, bindings, options) {
kendo.data.Binder.fn.init.call(this, element, bindings, options);
var binding = this.bindings.keyPress;
$(element.input).bind("keypress", function(e) {
var values = { a: 1, b: 2, c: 3 };
binding.get(e, values); //DOESN'T WORK!
});
},
refresh: function () { }
});
var viewModel = kendo.observable({
onKeyPress: function (e, values) {
$("#output").append("<div>keyPress (see console.log)</div>");
console.log(e);
console.log(values);
}
});
kendo.bind("#body", viewModel);
</script>