zoukankan      html  css  js  c++  java
  • 一款异步加载下拉框插件

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

    生成后的Html页面代码

    代码
    <div style=" 200px;" class="dhx_combo_box ">
    <input type="text" autocomplete="off" class="dhx_combo_input" style=" 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("&", "&amp;");
    }

    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);
    }
    }
    }
  • 相关阅读:
    Cocos2Dx(3)——动作类备忘
    npm publish发布包时出现403错误no_perms Private mode enable, only admin can publish this module:
    使用node.js定义一个web服务器
    node.js中events模块应用
    session应用:验证用户是否已登录
    简单实现三级导航栏
    promise对象代替回调函解决异步操作
    js一行代码解实现数组去重和排序
    中英文切换导航栏(最简单)
    错误:localhost将您重定向的次数过多
  • 原文地址:https://www.cnblogs.com/chenjunsheep/p/1775743.html
Copyright © 2011-2022 走看看