[英]Passing dynamically Data Object in the data using AutoSuggest jQuery plugin
AutoSuggest jQuery Plugin requires an already available Data Object in order to run. AutoSuggest jQuery插件需要一个已经可用的数据对象才能运行。 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 以下代码段在Firebug中引发错误
availableTeachers is not defined
未定义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,
});
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. 更多的测试,我predifined
availableTeachers
一些伪数据和i中的用户选择后,用真实数据填充它lesson.name
在第一输入端。
Second input keeps seeing only the dummy data
第二个输入仅看到虚拟数据
So far, it seems that autoSuggest plugin can only use static Data Objects or JSON requests. 到目前为止,似乎autoSuggest插件只能使用静态数据对象或JSON请求。
Where is availableTeachers defined? 凡被定义availableTeachers? 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.
这是不够的,只有将其指定的lambda函数内部的值,因为该变量的作用域是局部的,除非它在全球范围内创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.