Ajax 计时问题:计数被结果覆盖
在这个问题上,我几乎视而不见:我正在使用KendoUI的数据源和一些过滤器来进行某种ajax搜索:。结果是我的函数没有按正确的顺序执行。我的数据源和KendooObservable如下所示:Ajax 计时问题:计数被结果覆盖,ajax,datasource,kendo-ui,Ajax,Datasource,Kendo Ui,在这个问题上,我几乎视而不见:我正在使用KendoUI的数据源和一些过滤器来进行某种ajax搜索:。结果是我的函数没有按正确的顺序执行。我的数据源和KendooObservable如下所示: var jobTemplate = kendo.template($('#job-stub').html()); var jobCount = new kendo.data.ObservableObject({ count: 20 }); jobCount.bind('change', funct
var jobTemplate = kendo.template($('#job-stub').html());
var jobCount = new kendo.data.ObservableObject({
count: 20
});
jobCount.bind('change', function(){
if(this.count == 0){
$('#result-wrapper').prepend('<h2>Er zijn geen vacatures gevonden.</h2>');
} else if(this.count == 1){
$('#result-wrapper').prepend('<h2>Er is <span class="blue">'+this.count+'</span> vacature gevonden.</h2>');
} else {
$('#result-wrapper').prepend('<h2>Er zijn <span class="blue">'+this.count+'</span> vacatures gevonden.</h2>');
}
});
var jobData = new kendo.data.DataSource({
transport: {
read: {
url: '/jobs/json/search',
dataType: 'json',
data: {
job_matching_function: function(){
return $('#job_matching_function').val();
},
job_matching_type: function(){
return $('#job_matching_type').val();
},
job_matching_hours: function(){
return $('#job_matching_hours').val();
},
job_matching_education: function(){
return $('#job_matching_education').val();
}
}
}
},
schema: {
data: 'results'
},
change: function(){
$('#result-wrapper').html(kendo.render(jobTemplate, this.view()));
jobCount.set('count', this.view().length);
}
});
var jobTemplate=kendo.template($('#作业存根').html();
var jobCount=新的kendo.data.observeObject({
计数:20
});
jobCount.bind('change',function()){
如果(this.count==0){
$(“#结果包装器”).prepend('Er zijn geen vacations gevonden');
}else if(this.count==1){
$(“#结果包装器”).prepend('Er is'+this.count+'vacation gevonden');
}否则{
$(“#结果包装器”).prepend('Er zijn'+this.count+'vacations gevonden');
}
});
var jobData=new kendo.data.DataSource({
运输:{
阅读:{
url:“/jobs/json/search”,
数据类型:“json”,
数据:{
作业匹配函数:函数(){
return$('#job_matching_function').val();
},
作业匹配类型:函数(){
返回$('#作业匹配类型').val();
},
作业匹配小时数:函数(){
return$('#job_matching_hours').val();
},
工作匹配教育:功能(){
return$(“#工作与教育匹配”).val();
}
}
}
},
模式:{
数据:“结果”
},
更改:函数(){
$('#result wrapper').html(kendo.render(jobTemplate,this.view());
jobCount.set('count',this.view().length);
}
});
当其中一个过滤器被点击时,我运行jobData.read()代码>。偶尔,结果计数不会显示。有人知道为什么吗
谢谢
- 史蒂文
史蒂文,我从未尝试过在读取中使用4个匿名方法,不确定它的行为-尝试使用一个读取调用和一个返回。然后您可以使用完整事件,如图所示 Steven,我从来没有尝试过在read中使用4个匿名方法,不知道它的行为如何-尝试使用一个read调用和一个return。然后您可以使用完整事件,如图所示