[英]Show Message When DataSource Returns Empty for a Kendo ComboBox
使用Kendo MVC Helper控件时,我正在使用JavaScript(JS)管理表单的其他方面。 我有一个Kendo DropDown控件的JS引用,该控件将“搜索文本”传递给API调用。 显然,搜索文本可能不会返回任何结果。
如果没有返回结果,我想显示一条消息(和/或执行其他操作)。 但是,我在寻找合适的事件时遇到了麻烦。
这些是“似乎”可用于此目的的唯一事件:
题:
使用JavaScript,当API调用返回空数据集时如何显示消息?
我将继续并包括一些代码...尽管您不需要它来回答这个特定问题。
样本标记:
<div class="input-group input-group-sm" style="width: 600px">
<span class="input-group-addon input-sm text-align">Search</span>
@(Html.Kendo().ComboBox()
.Name("ddlMeter")
.Filter("contains")
.Placeholder("Type Meter Name or Number...")
.DataTextField("Text")
.DataValueField("Value")
.AutoBind(false)
.MinLength(4)
.DataSource(source => source.Read(read => read.Action("findmeter", "rtf", new { area = "documents" }))
.ServerFiltering(true))
.HtmlAttributes(new { style = "width:100%;" }))
</div>
JAVASCRIPT示例:
这只是一个示例控制器...
函数PageController(options){
var that = this,
empty = {},
dictionary = {
elements: {
form: null,
ddlMeter: null,
},
instances: {
ddlMeter: null
},
selectors: {
form: 'form',
ddlMeter: '#ddlMeter'
}
};
var initialize = function (options) {
that.settings = $.extend(empty, $.isPlainObject(options) ? options : empty);
// Elements
dictionary.elements.form = $(dictionary.selectors.form);
dictionary.elements.ddlMeter = $(dictionary.selectors.ddlMeter, dictionary.elements.form);
// Kendo Objects
dictionary.instances.ddlMeter = dictionary.elements.ddlMeter.data('kendoComboBox');
// Events
dictionary.instances.ddlMeter.bind('change', that.on.change.ddlMeter);
dictionary.instances.ddlMeter.bind('dataBind', that.on.databind.ddlMeter);
};
this.on = {
change: {
ddlMeter: function (e) {
// This only fires if they CHANGE the controls choice on an existing dataset
},
databind: {
ddlMeter: function (e) {
// This wont do it if the set is empty
}
},
};
initialize(options);
};
我认为您需要改用RequestEnd
事件。 如果我没记错的话,可以使用以下语法获取事件内部数据源的句柄:
this.dataSource.data();
要么
.DataSource(source => source.Read(read => read.Action("findmeter", "rtf", new { area = "documents" }))
.Events(e=>e.RequestEnd("requestEnd"))
.ServerFiltering(true))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.