Javascript / Phonegap中的对象未定义

时间:2014-02-10 17:09:16

标签: javascript object cordova

我的代码如下:

var app = {
    info: {
        one: "1",
        two: "abc",
        three: "cba",
        four: "abcd",
        objOne: {
            one: 1201, 
            two: 52,
            three: 941,
            four: "message"
        },
        objTwo: {
            one: "50.07995",
            two: "8.248324"
        }
        }
    }

当我尝试通过app.info.objOne.one访问变量时,我得到'undefined'

我真的不知道为什么我无法获得对象的属性,我很感谢任何建议。

1 个答案:

答案 0 :(得分:0)

似乎您忘记在代码末尾插入结束的}大括号。

这个工作正常。

var app = {
    info: {
        one: "1",
        two: "abc",
        three: "cba",
        four: "abcd",
        objOne: {
            one: 1201, 
            two: 52,
            three: 941,
            four: "message"
        },
        objTwo: {
            one: "50.07995",
            two: "8.248324"
        }

    }
 } //you forgot this one

 alert(app.info.objOne.one);