在这个问题上,我几乎瞎了眼:我正在使用KendoUI的数据源和一些过滤器来做一种ajax搜索:http://www.high-quality.nl/kandidaten/vacatures/。发生的情况是我的函数没有按正确的顺序执行。我的数据源和 kendoObservable 看起来像这样:
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);
}
});
当其中一个过滤器被单击时,我会运行jobData.read();
.时不时地显示结果计数。有人知道为什么吗?
谢谢
- 史蒂文
史蒂文,我从未尝试过在读取中使用 4 个匿名方法,不确定它的行为方式 - 尝试进行一次读取调用并返回一次。然后,您可以使用完整事件,如本文所示。