账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Javascript 如何动态在数组里添加对象?
    15
    0

    后端发过来的数据格式是这样的:

    var a = [
        { "title": "56岁及以上", "color": "#c12552", "value": "30", "sql": " select a00 from ipad_Analysis where s1='1' and  s10='硕士研究生及以上'" },
        { "title": "46岁至55岁", "color": "#ff6600", "value": "8", "sql": " select a00 from ipad_Analysis where  s1='1' and  s10='大学本科'" },
        { "title": "其他", "color": "#f5c700", "value": "13", "sql": " select a00 from ipad_Analysis where  s1='1' and  s10='大学专科'" }
    ];
    
    

    由于我制作的界面使用了echart,所以必须把这个数组赋值给我的echartData中,如果只有着三条数据的话,那么写死就行了,

    
    var echartData = [{
        value: parseInt(a[0].value),
        name: a[0].title
    }, {
        value: parseInt(a[1].value),
        name: a[1].title
    }, {
        value: parseInt(a[2].value),
        name: a[2].title
    }
    ];
    

    如果后端发过来的数据不止有三个对象,我怎么动态生成一个有多个对象(根据后端发过来的数据)的数组呢?

    谢谢!

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 妖王大叔 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部