javascript - 组成对象数据出错
黄舟
黄舟 2017-04-10 15:38:31
0
2
720

这个组不成像下下面那样的对你数据,提示:
Uncaught TypeError: Cannot set property 'userid' of undefined index.html:127
(anonymous function)
不知道userid那里为什么错了

var data = {};
data['id'] = 'waiting' + Date.parse(new Date());
data['content'] = "禁止IOS系统下长按图片弹出图片保存菜单?";
data['inputtime'] = 0;
data['position'] = "22.5446,45.2544";
data['synchrotime'] = Date.parse(new Date());
data['myaddress'] = "广州中国人民银行";
data['showaddress'] = "true";

data.UserInfo['userid'] = "654df5d";
data.UserInfo['nickname'] = "好人";
data.UserInfo['age'] = "22";
data.UserInfo['sex'] = "true";
data.UserInfo['company'] = "华润万家";
data.UserInfo['avatar'] = "http://a6a9bb2b2535f09d119f.b0.upaiyun.com/apicloud/b2ab1120806d2f7f47cf502d4a9456fa.jpg";

data.DeviceInfo['system'] = "api.systemType";
data.DeviceInfo['vendor'] = "api.deviceName";
data.DeviceInfo['model'] = "api.deviceModel";

console.log(data);
var _data = 
    {
        "id": "waiting1438771689000",
        "content": "地垮台大",
        "inputtime": 0,
        "position": "22.546162,114.070908",
        "description": "地垮台大",
        "synchrotime": 1438771689000,
        "showaddress": "0",
        "UserInfo": {
            "userid": "554cc3198ae6c423a43e0f",
            "nickname": "88888888888",
            "age": "5155",
            "sex": "true",
            "company": "奔奔娱乐有限公司",
            "avatar": "http://a6a9bb2b2535f09d119f.b0.upaiyun.com/apicloud/b2ab1120806d2f7f47cf502d4a9456fa.jpg"
        }, 
        "DeviceInfo": {
            "system": "android", 
            "model": "Droid4X", 
            "vendor": "MIT"
        }
    };
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回覆(2)
伊谢尔伦

加data["UserInfo"]={}试试

洪涛

data.UserInfodata.DeviceInfo 都还没有赋值呢

var data = {};
data.UserInfo = {}, data.DeviceInfo = {};
data.UserInfo['userid'] = '654df5d';

这样就可以了

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板