使用 AutoSuggest jQuery 插件动态传递数据中的数据对象

发布于 2024-09-14 15:45:02 字数 1493 浏览 9 评论 0原文

AutoSuggest jQuery 插件 需要已有的数据对象才能运行。 我需要使用第一个输入中的用户选择作为第二个输入中的数据。

以下代码片段在 firebug 中引发错误

availableTeachers 未定义

var labs = {lesson:
                [
                    {
                        name: "FOO LESSON",
                        professors: [
                            { lab: "FOO TEACHER [Monday 3 pm]" },
                            { lab: "FOO TEACHER [Thursday 7 pm]" }
                        ]
                    },
                    {
                        name: "FOO LESSON",
                        professors: [
                            { lab: "FOO TEACHER [Tuesday 10 am]" }
                        ]
                    }
                ]
        };

firstStep.find("form input[type=text]").autoSuggest(labs.lesson, {
    selectedItemProp: "name",
    searchObjProps: "name",
    selectionLimit: 1,
    resultClick: function(data){
        availableTeachers = data.attributes;
    },
});

secondStep.find("form input[type=text]").autoSuggest(availableTeachers.professors, {
    selectedItemProp: "lab",
    searchObjProps: "lab",
    selectionLimit: 1,
});

编辑

更多测试,我使用一些虚拟数据预定义了availableTeachers,并在用户选择lesson.name 在第一个输入中。

第二个输入始终只看到虚拟数据

到目前为止,autoSuggest 插件似乎只能使用静态数据对象或 JSON 请求。

AutoSuggest jQuery Plugin requires an already available Data Object in order to run.
I need to use the user's selection from the first input as data in the second input.

The following snippet throws an error in firebug

availableTeachers is not defined

var labs = {lesson:
                [
                    {
                        name: "FOO LESSON",
                        professors: [
                            { lab: "FOO TEACHER [Monday 3 pm]" },
                            { lab: "FOO TEACHER [Thursday 7 pm]" }
                        ]
                    },
                    {
                        name: "FOO LESSON",
                        professors: [
                            { lab: "FOO TEACHER [Tuesday 10 am]" }
                        ]
                    }
                ]
        };

firstStep.find("form input[type=text]").autoSuggest(labs.lesson, {
    selectedItemProp: "name",
    searchObjProps: "name",
    selectionLimit: 1,
    resultClick: function(data){
        availableTeachers = data.attributes;
    },
});

secondStep.find("form input[type=text]").autoSuggest(availableTeachers.professors, {
    selectedItemProp: "lab",
    searchObjProps: "lab",
    selectionLimit: 1,
});

EDIT

More testing, i predifined availableTeachers with some dummy data and i populate it with real data after the user selects a lesson.name in the first input.

Second input keeps seeing only the dummy data

So far, it seems that autoSuggest plugin can only use static Data Objects or JSON requests.

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

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

发布评论

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

评论(1

终陌 2024-09-21 15:45:02

availableTeachers 定义在哪里?您应该有一个创建变量的地方。仅在 lambda 函数内为其赋值是不够的,因为该变量的作用域是局部的,除非它是在全局作用域中创建的。

Where is availableTeachers defined? You should have some place where the variable is created. It is not enough to only assign it a value inside the lambda function, since the scope of that variable is local, unless it's created in the global scope.

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