大家好,我已经编写了以下代码来查找longpress
当我没有绑定任何数据并尝试给我正确的结果时哪个工作正常
<div data-options="dxView : { name: 'lngPress', title: 'lngPress' } ">
<div data-options="dxContent : { targetPlaceholder: 'content' } ">
<div data-bind="event: { mousedown: function() { myFunction() },mouseleave: function() { mymouseleave() },mouseup: function() { mymouseup() } }">
Mouse over me
</div>
</div>
我的脚本如下
var longpress = 100;
var start;
testMobileApplication.lngPress = function (params) {
var viewModel = {
myFunction: function () {
start = new Date().getTime();
},
mymouseleave: function () {
start = 0;
},
mymouseup: function () {
if (new Date().getTime() >= (start + longpress)) {
alert('long press!');
} else {
alert('short press!');
}
}
};
return viewModel;
};
但是当我绑定一些数据时,相同的代码无法按预期工作
<div data-options="dxView : { name: 'lngPress', title: 'lngPress' } ">
<div data-options="dxContent : { targetPlaceholder: 'content' } ">
<div data-bind="dxList: { dataSource: dataSource }" id="pr">
<div data-options="dxTemplate: { name:'item' }" data-bind="event: { mousedown: function() { myFunction() },mouseleave: function() { mymouseleave() },mouseup: function() { mymouseup() } }">
<span class="dx-field-label" data-bind="text: name"></span>
<span class="dx-field-label" data-bind="text: hire"></span>
</div>
</div>
</div>
脚本如下
var longpress = 100;
var start;
testMobileApplication.lngPress = function (params) {
var viewModel = {
myFunction: function () {
start = new Date().getTime();
},
mymouseleave: function () {
start = 0;
},
mymouseup: function () {
if (new Date().getTime() >= (start + longpress)) {
alert('long press!');
} else {
alert('short press!');
}
},
dataSource: [
{ id: 1, name: "Bob", hire: 2005 },
{ id: 2, name: "John", hire: 2007 },
{ id: 3, name: "Frank", hire: 2001 },
{ id: 4, name: "Robert", hire: 2007 },
]
};
return viewModel;
};
所以有人可以帮助我吗