Jquery 移动滑动事件未触发 Knockout.js
Jquery mobile Swipe event is not firing with Knockout.js
我有这个 html table,我需要浏览 "swipe" 上的页面。
onSwipeRight = function () {
gridPager.CurrentPage(gridPager.CurrentPage() + 1);
},
onSwipeLeft = function () {
gridPager.CurrentPage(gridPager.CurrentPage() - 1);
},
<table width="100%" border="0" cellspacing="0" cellpadding="0" data-bind="swiperight: onSwipeRight, swipeleft: onSwipeLeft">
<tr class=" filterpanel">
<td><span class="rowMove" style="background: none;"></span></td>
<td><input type="text" data-bind="value: filtercus.name, valueUpdate: 'afterkeydown'"></td>
<td><input type="text" data-bind="value: filtercus.code, valueUpdate: 'afterkeydown'"></td>
<td><input type="text" data-bind="value: filtercus.description, valueUpdate: 'afterkeydown'" style="width: 295px"></td>
</tr>
</table>
当我在点击事件上调用相同的 JS 方法时,事件成功触发。但是在 Swipe 上它不起作用。
如果您需要通过敲除来处理滑动事件,而不是直接处理,请使用 event
绑定:
data-bind="event:{swiperight: onSwipeRight}"
显然,onSwipeLeft
和onSwipeRight
必须在您的视图模型中声明。
此外,我相信您已经知道传递给您的敲除事件处理函数的前两个参数是
data
(上下文中的 ViewModel)
event
(jQuery 事件)
这意味着,您也可以只使用一个函数来处理左右滑动方向:
onSwipe = function (data, event) {...
...因为 jQuery.Event.type 将是 "swiperight"
或 "swipeleft"
。
我有这个 html table,我需要浏览 "swipe" 上的页面。
onSwipeRight = function () {
gridPager.CurrentPage(gridPager.CurrentPage() + 1);
},
onSwipeLeft = function () {
gridPager.CurrentPage(gridPager.CurrentPage() - 1);
},
<table width="100%" border="0" cellspacing="0" cellpadding="0" data-bind="swiperight: onSwipeRight, swipeleft: onSwipeLeft">
<tr class=" filterpanel">
<td><span class="rowMove" style="background: none;"></span></td>
<td><input type="text" data-bind="value: filtercus.name, valueUpdate: 'afterkeydown'"></td>
<td><input type="text" data-bind="value: filtercus.code, valueUpdate: 'afterkeydown'"></td>
<td><input type="text" data-bind="value: filtercus.description, valueUpdate: 'afterkeydown'" style="width: 295px"></td>
</tr>
</table>
当我在点击事件上调用相同的 JS 方法时,事件成功触发。但是在 Swipe 上它不起作用。
如果您需要通过敲除来处理滑动事件,而不是直接处理,请使用 event
绑定:
data-bind="event:{swiperight: onSwipeRight}"
显然,onSwipeLeft
和onSwipeRight
必须在您的视图模型中声明。
此外,我相信您已经知道传递给您的敲除事件处理函数的前两个参数是
data
(上下文中的 ViewModel)event
(jQuery 事件)
这意味着,您也可以只使用一个函数来处理左右滑动方向:
onSwipe = function (data, event) {...
...因为 jQuery.Event.type 将是 "swiperight"
或 "swipeleft"
。