使用 jQuery 和 Json 填充级联选择菜单

发布于 2025-01-04 04:26:13 字数 1389 浏览 0 评论 0原文

我需要在三层级联菜单中显示数据,所有数据都通过 jsonp 填充(跨域问题)。将只有一个 jsonp 文件(每个子菜单不单独)。此外,jsonp 可以(应该)加载一次,而不是由每个连续的选择更改触发。

我在 jQuery 方面遇到了困难,弄清楚如何根据父选择过滤检索到的数据。以下是我到目前为止所拥有的:

HTML

<select id="typeFilter">
   <option value="" />  
</select>
<select id="typeFilter">
    <option value="" />
</select>
<select id="userFilter">
   <option value="" />
</select>

JSON

{"filters": {
    "productFilter": {
        "prod1": "Product 1",
        "prod2": "Product 2",
        "prod3": "Product 3",
    },
    "typeFilter": {
        "type1": 
            { 
                "Type 1": [
                    "subtype1": "Sub Type 1",
                    "subtype2": 
                        {
                            "Sub Type 2" : [
                                "subSubtype1": "Sub-Sub Type 1",
                                "subSubtype2": "Sub-Sub Type 2",
                                "subSubtype3": "Sub-Sub Type 3"     
                            ]
                        },
                    "subtype3": "Sub Type 3",
                ]
            },
        "type2": "Type 2",
        "type3": "Type 3",
    },
    "userFilter": {
        "user1": "user 1",
        "user2": "user 2",
        "user3": "user 3",
    }
}}

JQUERY

...这是我遇到问题的部分。

I have a requirement to display data in cascading menus three deep, with all of the data being populated via jsonp (cross-domain issues). There will be just one jsonp file (not separate for each submenu). Moreover, the jsonp can (should) be loaded once rather than triggered by each successive select change.

I'm having a hard time with the jQuery, figuring out how to filter the retrieved data based on the parent select. Below is what I have so far:

HTML

<select id="typeFilter">
   <option value="" />  
</select>
<select id="typeFilter">
    <option value="" />
</select>
<select id="userFilter">
   <option value="" />
</select>

JSON

{"filters": {
    "productFilter": {
        "prod1": "Product 1",
        "prod2": "Product 2",
        "prod3": "Product 3",
    },
    "typeFilter": {
        "type1": 
            { 
                "Type 1": [
                    "subtype1": "Sub Type 1",
                    "subtype2": 
                        {
                            "Sub Type 2" : [
                                "subSubtype1": "Sub-Sub Type 1",
                                "subSubtype2": "Sub-Sub Type 2",
                                "subSubtype3": "Sub-Sub Type 3"     
                            ]
                        },
                    "subtype3": "Sub Type 3",
                ]
            },
        "type2": "Type 2",
        "type3": "Type 3",
    },
    "userFilter": {
        "user1": "user 1",
        "user2": "user 2",
        "user3": "user 3",
    }
}}

JQUERY

...this is the part I'm having trouble with.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

允世 2025-01-11 04:26:13

您尝试过解析 JSON 吗?

这将有助于开始一些非常简单的 jQuery 示例:http://docs.jquery.com/How_jQuery_Works

此页面将帮助您解析 JSON: http://api.jquery.com/jQuery.parseJSON< /a>

祝你好运

Have you had a go at trying to parse the JSON?

Thiss will help get started with some very simple jQuery examples: http://docs.jquery.com/How_jQuery_Works

This page will help you out with parsing the JSON: http://api.jquery.com/jQuery.parseJSON

Good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文