2012-03-10 2 views
3

noty 플러그인과 plum 장바구니 jQuery를 사용하여 다음과 같은 jQuery를 보유하고 있습니다. 첫 번째 코드 블록은 yes/no를 올바르게 경고하고 카트를 올바르게 비 웁니다.jQuery noty 플러그인을 사용하여 true 또는 false를 반환하려면 어떻게해야합니까?

코드의 두 번째 블록은 예를 보여줍니다/어떤 메시지가 제대로 noty를 사용하지하지만 그것은 참/거짓이 너무 카트 밤은이 비워 반환하지 않습니다. jQuery를에

임 정말 새로운 그래서 아마 뭔가를 분명 누락! 어떤 도움을 주시면 감사하겠습니다 :

//This works.. 
emptycart: function() { 
    if (!confirm('Are you sure you want to empty your cart?')) { 
     return false; 
    } 
}, 

//This doesnt work.. 

emptycart: function() { 
    confirm.call(this, noty({ 
     text: 'Are you sure you want to empty the cart ?', 
     buttons: [ 
      {type: 'button green', text: 'Ok', click: function() { return false; } }, 
      {type: 'button pink', text: 'Cancel', click: function() { return true; } } 
     ], 
     closable: false, 
     timeout: false 
     }), 
     true 
    ); 
    return false; 
}, 
+0

jsfiddle을 만들 수 있습니까? – MCSI

답변

1

는 음, 플러그인은 콜백을 사용할 때 그래서 당신은 비동기 방식으로 생각해야 콜백을 받고있다.

/** 
* @param {function} onConfirm : Receives true or false as argument, depending on the user choice 
*/ 
emptycart: function (onConfirm) { 
    confirm.call(this, noty({ 
     text: 'Are you sure you want to empty the cart ?', 
     buttons: [ 
      { 
       type: 'button green', 
       text: 'Ok', 
       click: function() { 
        //Do other stuff if you want... 
        onConfirm(true); 
       } 
      }, 
      { 
       type: 'button pink', 
       text: 'Cancel', 
       click: function() { 
        //Do other stuff if you want... 
        onConfirm(false); 
       } 
      } 
     ], 
     closable: false, 
     timeout: false 
    }), true); 
} 

위, 사용자가 어느 버튼을 클릭 할 때 호출되는 "onConfirm"는 callbackfunction를 보내드립니다. 이 함수는 Ok 또는 Cancel을 클릭했는지 알려주는 하나의 부울 인수를받습니다.

관련 문제