【发布时间】:2012-11-07 21:15:28
【问题描述】:
当我尝试使用 jquery deferreds 时,使用 vktemplate 并不能很好地工作。由于 vktemplate 进行了自己的 ajax 调用,所以 deferred 在 vktemplate 完成其工作和可选回调之前得到解决。我如何设置 vk 以便在这两件事发生之前不会解决承诺?
$(document).on('click', '.ajax', function() {
$.when(ajax1('<p>first</p>'),
ajax2('<p>second</p>'),
ajax3('<p>third</p>'))
.then(function(results1, results2, results3) {
console.log(results1);
$('.document').append(results1);
$('.document').append(results2);
$('.document').append(results3);
alert('all ajax done');
});
});
function ajax1(data) {
$.ajax({
type: 'post',
url: 'templates/test_template.tmpl',
data: "data=" + data,
dataType: 'json',
success: function (returnedData) {
$('#resultsDiv').vkTemplate('templates/test_template.tmpl', returnedData, function () {
//vk callback
//possibly call my resolve here?
});
}
});
}
function ajax2(data){//more of the same}
【问题讨论】:
标签: javascript jquery jquery-templates jquery-deferred