前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Object.keys和Object.values

Object.keys和Object.values

作者头像
从入门到进错门
发布2018-08-21 16:37:14
5270
发布2018-08-21 16:37:14
举报
文章被收录于专栏:前端菜鸟变老鸟

需求,数据格式是这样的,然后使用baidutemplate渲染页面的时候列数未知。

数据

代码语言:javascript
复制
    var data = {"state":true,"data":{"key":"idd:ast:alldata","data":[{"k0":"2018-05-19","k1":201970,"k2":21732,"k3":9.29,"k4":7320,"k5":244,"k6":30.01,"k7":194650,"k8":21488,"k9":9.06},{"k0":"2018-05-18","k1":191160,"k2":20286,"k3":9.42,"k4":7240,"k5":231,"k6":31.34,"k7":183920,"k8":20055,"k9":9.17},{"k0":"2018-05-17","k1":192805,"k2":20452,"k3":9.43,"k4":6375,"k5":268,"k6":23.79,"k7":186430,"k8":20184,"k9":9.24},{"k0":"2018-05-16","k1":191955,"k2":20131,"k3":9.54,"k4":4765,"k5":198,"k6":24.07,"k7":187190,"k8":19933,"k9":9.39},{"k0":"2018-05-15","k1":186710,"k2":19245,"k3":9.7,"k4":3065,"k5":188,"k6":16.3,"k7":183645,"k8":19057,"k9":9.64},{"k0":"2018-05-14","k1":46305,"k2":5253,"k3":8.81,"k4":415,"k5":23,"k6":18.04,"k7":45890,"k8":5230,"k9":8.77}],"wordbook":{"k0":"\u65e5\u671f","k1":"\u83b7\u53d6\u603b\u6570","k2":"\u83b7\u53d6\u603b\u4eba\u6570","k3":"\u4eba\u5747\u83b7\u53d6\u6570","k4":"\u6d88\u8017\u603b\u6570","k5":"\u6d88\u8017\u603b\u4eba\u6570","k6":"\u4eba\u5747\u6d88\u8017\u6570","k7":"\u672a\u6d88\u8017\u603b\u6570","k8":"\u672a\u6d88\u8017\u603b\u4eba\u6570","k9":"\u4eba\u5747\u672a\u6d88\u8017\u6570"}}};

解决方案1:

html代码:

代码语言:javascript
复制
<tr>
    <%for(var item_title in wordbook){ %>
        <th width="auto"><%=wordbook[item_title]%></th>
    <%}%>
</tr>
说明:

使用for in 循环获取循环变量,渲染的时候根据循环变量获取值。

解决方案2:

html代码:

代码语言:javascript
复制
Object.keys(wordbook).length
Object.values(wordbook).length
说明:

使用Object.keys()或者Object.values()获取循环变量,渲染的时候根据循环变量获取值。Object.keys()函数返回索引(不仅仅是数字),Object.values()函数返回值。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年07月30日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 需求,数据格式是这样的,然后使用baidutemplate渲染页面的时候列数未知。
    • 数据
      • 解决方案1:
        • 说明:
      • 解决方案2:
        • 说明:
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档