简体   繁体   English

WinJS listview项调用了Hander如何

[英]WinJS listview iteminvokedHanlder how to

I'm using the iteminvokedHandler and was wonder if there is a better way to interact with the listView. 我正在使用iteminvokedHandler,想知道是否有更好的方法与listView进行交互。

Currently using this: 当前正在使用此:

        WinJS.UI.processAll(root).then(function () {

            var listview = document.querySelector('#myNotePad').winControl;
            listview.addEventListener("iteminvoked", itemInvokedHandler,false);

            function itemInvokedHandler(e) {

                e.detail.itemPromise.done(function (invokedItem) {

                    myEdit();

                });
            };


        });

The problem is that everytime I click on the listview myEdit() is run and propagates within the listview. 问题是,每次我单击列表视图时,myEdit()便会运行并在列表视图中传播。 I was wondering how to do it once and stop invoking listview until I am done with myEdit? 我想知道如何做一次并停止调用listview,直到完成myEdit为止? Is there a simpler way to handle such a situation as this? 有没有更简单的方法来处理这种情况?

Simple yet hard to see when you have a mind block and forget some of the basics (yes yes I'm still learning): 简单但难以看清,何时您有思维障碍却忘记了一些基础知识(是的,我仍在学习):

 var testtrue = true;      

       WinJS.UI.processAll(root).then(function () {

            var listview = document.querySelector('#myNotePad').winControl;
            listview.addEventListener("iteminvoked", itemInvokedHandler,false);

            function itemInvokedHandler(e) {

                e.detail.itemPromise.done(function (invokedItem) {

                  if (testtrue === true){

                    myEdit();

                  }  


                });
            };


        });

In myEdit: 在myEdit中:

    function myEdit() {

        var theelem = document.querySelector(".win-selected #myNotes");

        var gestureObject = new MSGesture();  
        gestureObject.target = theelem;
        theelem.gestureObject = gestureObject;

        theelem.addEventListener("pointerdown", pointerDown, false);

        theelem.addEventListener("MSGestureHold", gestureHold, false);


        function pointerDown(e) {
            e.preventDefault();
            e.target.gestureObject.addPointer(e.pointerId);
        }


        function gestureHold(e) {

            if (e.detail === e.MSGESTURE_FLAG_BEGIN && test === true) {
                e.preventDefault();
                    editNotes();

              } else {


                }

            console.log(e);
        }

        theelem.addEventListener("contextmenu", function (e) {
            e.preventDefault();}, false); //Preventing system menu

    };


    function editNotes() {

      //The Code I wish to execute

        return test = false;
    };

What I needed was a conditional statement so that it would run if true and not if false. 我需要的是一个条件语句,以便它在为true时运行,如果为false则运行。 That same test needed to be done in the gestureHold otherwise it would continue to fire myEdit on the invoked item because of the way the gesture is attached to the item the first time it is run. 必须在gestureHold中进行相同的测试,否则它将由于在第一次运行时将手势附加到项目的方式而继续在调用的项目上触发myEdit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM