2017-11-01 11 views
0

내 대화 상자에서 일반적인 모양과 느낌을 얻기 위해 일반적인 오류 대화 상자 기능을 구축했습니다. $.ajaxSetup.error 함수 내에서이 함수를 문제없이 호출합니다. 대화 상자의 호출을 통해 하나의 단추가 추가되었습니다. 내 버튼을 누르면 대화 상자가 닫히고 ajaxSetup.error 함수에서 호출되면 모서리의 X가 창이 닫힙니다.catch 블록에서 열면 jQuery UI 대화 상자를 닫을 수 없습니다.

내 JS 내에서 catch 블록 (NOT Ajax 호출) 대화 상자가 문제없이 열리지 만 내에서이 같은 함수를 호출하려고하면 내가 얻을 대화 상자를 닫습니다 다음과 같은 오류 내 단추를 클릭 할 때 :

을 당신은 내가 $(this)를 사용하여 대화 상자를 닫으려고 내 버튼에서 볼 수 있듯이

function __renderDialogOK(data) { 

    // This call renders the div to be displayed within 
    // the dialog. 
    var divMessage = __renderDialogBase(data); 

    $(divMessage).dialog(
     { 
      width: __getDialogWidth(), 
      resizeable: false, 
      modal: true, 
      hide: true, 
      show: true, 
      buttons: [ 
       { 
        text: "OK", 
        click: function (e) { 
         e.preventDefault(); 
         $(this).dialog("close"); 
         return false; 
        } 
       } 
      ], 
      open: function (e) { 
       $(this).parent().find("button:eq(1)").addClass('ui-state-default'); 
       $(this).parent().find("button:eq(1)").focus(); 
       $(this).on("keydown", function (event) { 
        if (parseInt(event.keyCode) === 13) { 
         $(this).parent() 
          .find("button:eq(1)").trigger("click"); 
         return false; 
        } 

        if (event.keyCode == 27) { 
         $(this).parent() 
          .find("button:eq(1)").trigger("click"); 
         return false; 
        } 
       }); 
      }, 
      close: function (e) { 
       $(this).off("keydown"); 
      } 
     } 
    ); 
} 

: 여기

0x800a138f - JavaScript runtime error: Unable to get property '_focusTabbable' of undefined or null reference

내 대화 상자를 생성하는 코드입니다. 또한 (글로벌) 함수 외부 변수를 사용하여 $(divMessage).dialog( 호출하여 반환 된 컨텍스트를 저장하는 시도했다.

내 고객이 현재 회사 표준으로 사용하고 있기 때문에 불행한 IE11에서만 발생하는 것으로 보입니다. 그래서 마침내 내 질문.

JavaScript 내에서 Catch 블록을 입력 할 때 모든 컨텍스트가 손실됩니까? 이 문제는 이전에 공개되었지만 스레드가 보이지 않고 있습니까? 이 비슷한 오류 메시지에 관한 다른 많은 스레드를 읽었지만 대화 상자가 아직 시작되지 않았기 때문에 내 인스턴스만큼 구체적이지 않은 것처럼 보입니다. 내 것이. 대화 상자가 화면에 나타납니다. 나는 단지 내 버튼으로 그것을 닫을 수 없다. 내 댓글에 확장

+0

포커스가 ** $ (this) .parent(). find ("button : eq (1)") 오류를 던지고 있습니다. ** $ (this) .off ("keydown"); – Krishjs

+0

먼저 @ 도움이되어 주셔서 감사합니다. 대단히 감사합니다. 두 줄을 모두 꺼내었지만 여전히 같은 오류가 발생합니다. 나는 왜 당신이 포커스를위한 keydown 이벤트의 비활성화를 언급했는지 확신 할 수 없었다. 이벤트를 비활성화하면 브라우저가 다시 초점을 맞추게됩니까? 더 이상 도움이되지 않을 경우 대단히 감사하겠습니다. – pachyderm94

+0

@Krishjs 내 appologies 나는 편집자를 보았고 Nisse가 의견을 게시했다고 생각했습니다. 도와 주셔서 감사합니다. :-) 미안하다. – pachyderm94

답변

0

,이 검사 것 :

 open: function (e) { 
      $(this).parent().find("button:eq(1)").addClass('ui-state-default'); 
      $(this).parent().find("button:eq(1)").focus(); 
      $(this).on("keydown", function (event) { 
       if (parseInt(event.keyCode) === 13) { 
        $(this).parent() 
         .find("button:eq(1)").trigger("click"); 
        return false; 
       } 

       if (event.keyCode == 27) { 
        $(this).parent() 
         .find("button:eq(1)").trigger("click"); 
        return false; 
       } 
      }); 
     } 

In most cases, the value of this is determined by how a function is called. It can't be set by assignment during execution, and it may be different each time the function is called. ES5 introduced the bind method to set the value of a function's this regardless of how it's called, and ES2015 introduced arrow functions which do provide their own this binding (it remains the this value of the enclosing lexical context).

그래서, open 콜백, $(this)open를 호출 한 객체를 참조합니다. 그것은 $(e.target)과 비슷합니다. 따라서 .on()을 통해 keydown 이벤트에 함수를 바인딩하면 $(this)은 더 이상 open 콜백이 아닙니다. keydown 콜백에 대한 참조입니다.

혼란을 피하려면 다른 일을 할 수 있습니다. 여기에 내가 먼저 시도 할 것입니다 :

 open: function (e) { 
      var $me = $(this); 
      var $parent = $(this).parent(); 
      $parent.find("button:eq(1)").addClass('ui-state-default'); 
      $parent.find("button:eq(1)").focus(); 
      $me.on("keydown", function (event) { 
       if (parseInt(event.keyCode) === 13) { 
        $parent 
         .find("button:eq(1)").trigger("click"); 
        return false; 
       } 

       if (event.keyCode == 27) { 
        $parent 
         .find("button:eq(1)").trigger("click"); 
        return false; 
       } 
      }); 
     } 

이것은 적절한 개체에 대한 적절한 참조를 유지하는 데 도움이됩니다.

+0

뒤틀린, 도움 주셔서 감사합니다. 고맙습니다. 내 참조를 보유하고 공개로 설정할 변수를 만들려고했다.나는 당신이 위에서 제안했던 것처럼 그것을 다시 시험해 보았다. 첫 번째 패스는 위에서 작성한 코드를 사용했지만 문제는 $ me와 $ parent 변수가 버튼 이벤트의 범위에 있지 않다는 것입니다. 그런 다음 두 변수를 open 이벤트 외부로 이동하고 클래스 수준 변수로 변경했습니다 (이전에 시도한 내용 임). 그러나 여전히 동일한 문제가 있습니다. 나는 이것이 모든 일을해야하고 나는 어리석은 짓을하고있을 것임에 틀림 없다고 느낀다. 그러나 단지 그것을 이해할 수 없다. – pachyderm94

+0

알아낼 것입니다. 내가 생각하는 바이올린을 만들어야 해. – Twisty

+0

고맙습니다. 나는 너무 조용히해서 미안해. 나는 수준 1과 2의 중대한 문제에 갇혀있다. 나는이 문제에 더 많은 것을 기울이지 않아서 미안합니다. 나는 결국 그것을 다시 만들 것이다. 도와 줘서 고마워. – pachyderm94