0

大家好,我已经编写了以下代码来查找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;
};

所以有人可以帮助我吗

4

1 回答 1

1

dxList 小部件具有特殊的回调itemHoldAction。您可以使用此回调来处理项目上的保持事件。Moveover,您将在 params 中获得项目数据和项目元素。

http://phonejs.devexpress.com/Documentation/ApiReference/Widgets/dxList/Configuration?version=13_2#itemHoldAction

如果您需要保持超时调整,请使用dxhold事件,如下所示:

$("#myElement").on("dxhold", { timeout: 1000 }, function() {
    alert("The element is being held during 1000 milliseconds");
});

http://phonejs.devexpress.com/Documentation/ApiReference/UI_Events?version=13_2#dxhold

希望它会有所帮助。

于 2014-04-03T20:58:27.447 回答