开发者

Chained select boxes using jquery and json

开发者 https://www.devze.com 2023-02-19 03:31 出处:网络
In the current web app which I\'m working, I would like to populate 4 select boxes using chained filtering.

In the current web app which I'm working, I would like to populate 4 select boxes using chained filtering.

Here's the json structure were's defined the relationship between the options available on each select box:

var example = { 
        "first_select_box_option_1" : [ {
            "" : [],
                "second_select_box_option_1" : [ {
                    "third_select_box_option_1" : [
                                                               "", 
                                                               "fourth_select_box_option_1"]
                }],
                "second_select_box_option_2" : [ {
                    "third_select_box_option_1" : [
                                                               "", 
                                                               "fourth_select_box_option_1"]
                }]
        }]
};

What I intend to do is hook some listeners to the firs three select boxes. Based on the made selection, the following ones should be filled with the proper options based on the previous json. Note that the json should be composed by multiple levels.

As example: on the first iteration, it the user selects the option *first_select_box_option_1* the second select box should be filled with the options *second_select_box_option_1* and 开发者_如何学编程*second_select_box_option_2*.

First of all, I would like to know if my json structure is adequate to represent the options available on each select box and the corresponding relations.


It is actually easier to make an AJAX(J) query which requests new JSON each time after user changes the value of the select. I am sorry for the blatant self promotion, but you might be interested to check the source of the remote version of jQuery Chained Selects plugin.

0

精彩评论

暂无评论...
验证码 换一张
取 消