我有一个 ASP.NET MVC 3 页面 (Razor),其中包含 Telerik ComboBox 和 Telerik Grid强>。我无法弄清楚如何使用 jquery 从组合框中获取值,然后使用该值来过滤(或重新绑定(bind))网格数据。
我的 Telerik ComboBox 加载了 *category_id*、*category_name*,并且我对其进行了编码,以便它可以自行过滤当我键入category_name 时,会动态地键入,直到找到完美匹配或选择一个项目。
任何有关执行此操作的最佳方法的指导,或有关使 jquery 更容易的提示(jquery 的智能感知?)将不胜感激。
这是 jquery 代码的一个代码段,该代码段会导致错误,并且页面不会加载任何数据。错误消息(来自 firebug)是: $("#Customers").data("tComboBox") 未定义,但我完全按照 Telerik 网站上的描述进行操作,当我查看页面源代码时,我看到了这个:
jQuery('#Categories').tComboBox...snipped the rest
这是我失败的函数:
function dataBinding(args) {
var categoryName = $("#Customers").data("tComboBox").value();
args.data = $.extend(args.data, { categoryName: categoryName });
}
最佳答案
您可以为 jQuery 添加智能感知,请阅读这篇文章了解如何操作:
要从 Telerik 组合框中检索所选值,请执行以下操作:
查看标记
// Assumed defenition of the combobox
<%= Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList(Model, "ProductID", "ProductName"))
.HtmlAttributes(new { style = "width: 200px; float: left; clear:both; margin-bottom: 230px;" })
%>
客户端脚本
// Will Get Selected Text
$("#DropDownList").data("tDropDownList").text()
// Will Get Selected Value
$("#DropDownList").data("tDropDownList").value()
为了进一步澄清 $("#DropDownList").data("tDropDownList").text()
中的“DropDownList”是在辅助方法中分配给控件的名称 ( Html.Telerik().DropDownList().Name("DropDownList")
) 因此您应该将上面发布的代码更改为 $("#Customers").data("< strong>tCustomers").value() 它应该可以工作。
PS:有关 Telerik ASP.NET MVC ComboBox API 的更多信息可以在 Telerik API 找到。
关于jquery - 如何使用 Telerik ComboBox 的选定值过滤 MVC Telerik Grid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6242965/