deferred.done (doneCallbacks [, doneCallbacks]) 정보
jQuery deferred.done (doneCallbacks [, doneCallbacks])본문
deferred.done (doneCallbacks [, doneCallbacks])
설명 : 지연된 개체가 해결 될 때 호출 할 처리기를 추가합니다.
이 deferred.done()메서드는 하나 이상의 인수를 받아들입니다. 인수는 모두 단일 함수 또는 함수 배열 일 수 있습니다. Deferred가 해결되면 doneCallbacks가 호출됩니다. 콜백은 추가 된 순서대로 실행됩니다. deferred.done()지연된 객체를 반환하기 때문에 추가 .done()메서드를 포함하여 지연된 객체의 다른 메소드를이 객체에 연결할 수 있습니다 . 해결 된되는 이연 때, doneCallbacks이 제공 한 인수하여 실행 resolve또는 resolveWith그들이 추가 된 순서대로 메소드 호출을. 자세한 내용은 지연 객체에 대한 설명서를 참조하십시오 .
예 :
이 jQuery.get메서드는 Deferred 객체에서 파생 된 jqXHR 객체를 반환하기 때문에 메서드를 사용하여 success 콜백을 연결할 수 있습니다 .done().
$.get( "test.php" ).done(function() {
alert( "$.get succeeded" );
});
사용자가 버튼을 클릭 할 때 Deferred 객체를 해결하여 여러 콜백 함수를 트리거합니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>deferred.done demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<button>Go</button>
<p>Ready...</p>
<script>
// 3 functions to call when the Deferred object is resolved
function fn1() {
$( "p" ).append( " 1 " );
}
function fn2() {
$( "p" ).append( " 2 " );
}
function fn3( n ) {
$( "p" ).append( n + " 3 " + n );
}
// Create a deferred object
var dfd = $.Deferred();
// Add handlers to be called when dfd is resolved
dfd
// .done() can take any number of functions or arrays of functions
.done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
// We can chain done methods, too
.done(function( n ) {
$( "p" ).append( n + " we're done." );
});
// Resolve the Deferred object when the button is clicked
$( "button" ).on( "click", function() {
dfd.resolve( "and" );
});
</script>
</body>
</html>
0
댓글 0개