一款异步加载下拉框插件
一款不错的基于JQuery的auto-complete插件,这款插件最大的好处就是我们能够得到{value, text}结构的数据,这与传统的下拉框很相似,非常适合用于项目开发。
生成后的Html页面代码

<div style="width: 200px;" class="dhx_combo_box ">
<input type="text" autocomplete="off" class="dhx_combo_input" style="width: 181px;">
<input type="hidden" name="LocalityObject" value="14523">
<input type="hidden" name="LocalityObject_new_value" value="false">
<img class="dhx_combo_img" src="http://www.cnblogs.com/Scripts/DHTMLX/codebase/imgs/combo_select.gif">
</div>
以下是基于MVC的一个例子
前台调用

<script type="text/javascript">
$(function() {
window.dhx_globalImgPath = "http://www.cnblogs.com/Scripts/DHTMLX/codebase/imgs/";
var z = new dhtmlXCombo("localobj", "LocalityObject", 200, 22);
z.enableFilteringMode(true, "http://www.cnblogs.com/Community/AsynchronousLocality", true, true);
});
</script>
后台代码

public ActionResult AsynchronousLocality()
{
XmlDocument xmldoc = new XmlDocument();
var content = BuildXML();
try
{
xmldoc.LoadXml(content);
}
catch(Exception e) {
}
return new XmlResult(xmldoc);
}
private string BuildXML()
{
string qstring = Request.QueryString["mask"].SafeString();
string start = Request.QueryString["pos"].SafeString();
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" ?>");
sb.AppendFormat("<complete{0}>", start.SafeInt().Equals(0)? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(qstring))
{
var communities = Service.ListLocalityByName(qstring);
for (var i = 0; i < communities.Count; i++)
{
if (i > 50) break;
sb.AppendFormat("<option value=\"{0}\">{1}</option>", communities[i].Id, communities[i].LocalityName);
}
}
sb.Append("</complete>");
return sb.ToString().Replace("&", "&");
}
XmlResult类

public class XmlResult : ActionResult
{
private object objectToSerialize;
/// <summary>
/// Initializes a new instance of the <see cref="XmlResult"/> class.
/// </summary>
/// <param name="objectToSerialize">The object to serialize to XML.</param>
public XmlResult(object objectToSerialize)
{
this.objectToSerialize = objectToSerialize;
}
/// <summary>
/// Gets the object to be serialized to XML.
/// </summary>
public object ObjectToSerialize
{
get { return this.objectToSerialize; }
}
/// <summary>
/// Serialises the object that was passed into the constructor to XML and writes the corresponding XML to the result stream.
/// </summary>
/// <param name="context">The controller context for the current request.</param>
public override void ExecuteResult(ControllerContext context)
{
if (this.objectToSerialize != null)
{
context.HttpContext.Response.Clear();
var xs = new System.Xml.Serialization.XmlSerializer(this.objectToSerialize.GetType());
context.HttpContext.Response.ContentType = "text/xml";
xs.Serialize(context.HttpContext.Response.Output, this.objectToSerialize);
}
}
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单