jQuery DoubleSelect / Cascade / Dependent / WalkRight Select菜单是否支持Ajax? [英] jQuery DoubleSelect/Cascade/Dependent/WalkRight Select Menus w/ Ajax Support?

查看:45
本文介绍了jQuery DoubleSelect / Cascade / Dependent / WalkRight Select菜单是否支持Ajax?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以从< select> 菜单中选择一个项目,然后填充第二个< select> menu。

Where you can pick an item from a <select> menu and then it populates a second <select> menu.

它的名称太多而且实现太多了。我正在寻找一个可以使用Ajax提取数据的最新版本(适用于最新版本的jQuery)。

It goes by too many names and there are too many implementations. I'm looking for an up-to-date one (works well with the latest version of jQuery) that can pull the data using Ajax.

任何人都可以推荐一个好的插件?

Can anyone recommend a good plugin?

推荐答案

// simple code but can be improved for need
function getListBoxValue(obj) {
        obj = $.extend({
            url: "",
            bindObj: null,
            emptyText: "exception",
            postValues : {},
            onComplete: function () { return true; },
            onError: function () { return false; }
        }, obj);

        $.ajax({
            url: obj.url,
            data: obj.postValues,
            type: "POST",
            dataType: "JSON",
            success: function (json) {
                var options;
                $.each(json, function (i, e) {
                    options += "<option value='" + e.Value + "'>" + e.Text + "</option>";
                });
                $(obj.bindObj).html(options);
                obj.onComplete(obj);
            },
            error: function (e, xhr) {
                $(obj.bindObj).html("<option value='-1'>" + obj.emptyText + "</option>");
                obj.onError(obj);
            }
        });
    }


// server response data json 
[{ "Value": 1, "Text": "text 1 " },{ "Value": 2, "Text": "text 2"}]


getListBoxValue({
    url: responseJsonDataURL, // example
    bindObj: $("select#YourID"), // example
    emptyText:"exception text", // example
    postValues: {"id": 45}, // example
    onComplete: _onCompleteFunction, // optional
    onError: _onErrorFunction // optional
})

这篇关于jQuery DoubleSelect / Cascade / Dependent / WalkRight Select菜单是否支持Ajax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆