2014-01-13 3 views
0

true 또는 false를 반환하고 프로젝트에서 작동하는 기본 확인 상자로 작동하는 jquery의 확인 모달 상자를 만들어야합니다. 프로젝트 간 사용자 정의 대화 상자 확인

var result = confirm("Are you sure you want exit"); 
if(result == false) 
    return false; 
else{ 
    //somethings are done here 
} 

과 Main.js에

그것은 다음과 같이 구현의 서면 나는 이런 식으로 전화를

... ..

function confirm(message){ 
    $("#alert_cust_message").html(message); 
    var returnValue = false; 
    $("#myAlert").dialog({ 
     modal: true, 
     minHeight: 100, 
     buttons: { 
      "OK": function() 
      { 
       $(this).dialog("close"); 
       returnValue = true; 
      }, 
      Cancel: function() 
      { 
       $(this).dialog("close"); 
       returnValue = false; 
      } 
     } 
    }); 
    $("#myAlert").parent().css('font-size','9pt'); 
    return returnValue; 
} 

지금 내가 직면하고있는 문제는에 관한 것입니다 반환 값 ...

기대되는 수익을 얻지 못하고 있습니다. 비동기 대화식으로 인한 것 같습니다.

이제 이것을 쉽게 해결할 수 있습니까?

어떤 도움

부탁드립니다 .. 감사합니다

당신은 콜백

function confirm(message, callback) { 
    $("#alert_cust_message").html(message); 
    var returnValue = false; 
    $("#myAlert").dialog({ 
     modal: true, 
     minHeight: 100, 
     buttons: { 
      "OK": function() { 
       $(this).dialog("close"); 
       callback(true); 
      }, 
      Cancel: function() { 
       $(this).dialog("close"); 
       callback(false); 
      } 
     } 
    }); 

    $("#myAlert").parent().css('font-size', '9pt'); 
} 

를 사용할 필요가

답변

0

다음

confirm('some message', function (result) { 
    if (result) {} 
}) 

데모 : Fiddle

+0

내가 콜백 부분을 피할 수있다? 콜백 기능을 사용하지 않고이를 수행 할 수있는 방법이 있습니까? – Saurabh

+0

@Saurabh 정말로 ... 또 다른 해결책은 Defferred/promise를 사용하는 것입니다. –

+0

솔루션을 제공해 주셔서 감사합니다 .... defferred.promise는 유망한 직업입니다. 그래서이 솔루션으로 돌아갈 것입니다. ** thanks ** again. – Saurabh