使用 AutoSuggest jQuery 插件动态传递数据中的数据对象
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.