我的json:
{
locale: "en",
title: "Survey",
focusFirstQuestionAutomatic: false,
pages: [
{
name: "livingEnvironment",
elements: [
{
type: "html",
name: "navigationWarning",
html: "To navigate "
},
{
type: "html",
name: "IntroEnvironment",
html: "We will now ask you questions about your living environment"
},
{
type: "text",
name: "numhousehold",
width: "auto",
title: "How many people (including yourself) lived in your household",
validators: [
{
type: "numeric",
text: "Please enter a number between 1 and 99.",
minValue: 1,
maxValue: 99
}
],
inputType: "number"
},
{
type: "multipletext",
name: "householdtype",
width: "auto",
title: "Of these, how many (including yourself) were:",
items: [
{
name: "children",
inputType: "number",
title: "Children under 18 years old",
validators: [
{
type: "regex",
text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
regex: "^(\\s*|\\d+)$"
}
]
},
{
name: "adults",
inputType: "number",
title: "Adults between 18-59 years old",
validators: [
{
type: "regex",
text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
regex: "^(\\s*|\\d+)$"
}
]
},
{
name: "seniors",
inputType: "number",
title: "Seniors (60+)",
validators: [
{
type: "regex",
text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
regex: "^(\\s*|\\d+)$"
}
]
},
{
name: "disabled",
inputType: "number",
title: "Disabled",
validators: [
{
type: "regex",
text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
regex: "^(\\s*|\\d+)$"
}
]
}
}
]}
我的javascript是:
function serverValidateQuestion(survey, options) {
console.log('Validation called');
console.log(options.data.householdtype);
console.log(options.data.householdtype.children);
所以我可以访问console.log(options.data.householdtype)
,它给我提供了in type类型中的项目列表。然而,我正在尝试访问从householdtype输入的"children“值。当我写console.log(options.data.householdtype.children)的时候,它给了我
`
无法读取“未定义”错误的属性。在谷歌控制台模式下,"console.log(options.data.householdtype)“为我提供了以下信息:
`“成人:"3”儿童:"3“残疾:"3”孕妇:"3“老年人:"3”原件:Object
但我只想访问孩子的值,而console.log(options.data.householdtype.children)
不起作用。此外,console.log(options.data.numhousehold)
确实给了我一个用户输入的值。此外,这些值来自用户在调查期间填写的输入框。请帮帮我。
发布于 2018-08-10 04:16:47
好的,我想出来了,因为在我的html文件console.log(options.data.householdtype)的第一页上,给出了未定义的。在我的html的第二页上,它是否找到了householdtype,然后它就可以访问console.log(options.data.householdtype.children);了,否则它就不能工作了。
https://stackoverflow.com/questions/51772062
复制相似问题