码迷,mamicode.com
首页 > Web开发 > 详细

js 把json字符串转为json对象

时间:2018-06-27 15:02:11      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:color   开启   报错   div   北京市   .data   数组   child   []   


   <input type="hidden" name="data" id="data" value=‘[{"name":"北京","value":1,"children":[{"name":"北京市1","value":12,"children":[{"name":"朝阳区1","value":13,"children":[]},{"name":"朝阳区2","value":14,"children":[]},{"name":"朝阳区3","value":15,"children":[]},{"name":"朝阳区4","value":16,"children":[]}]},{"name":"北京市2","value":17,"children":[]},{"name":"北京市3","value":18,"children":[]},{"name":"北京市4","value":19,"children":[]}]},{"name":"天津","value":2,"children":[{"name":"天津市1","value":51,"children":[]}]}]‘ />
[{},{}] 正确
[{},{},] 转json对象是报错 (直接写数组不报错)
var
Jsondata = $("#data")[0].defaultValue;
var jsonobj = JSON.parse(Jsondata); layui.formSelects.data(‘select15‘, ‘local‘, { arr: jsonobj, linkage: true ////开启联动模式 } );

 

js 把json字符串转为json对象

标签:color   开启   报错   div   北京市   .data   数组   child   []   

原文地址:https://www.cnblogs.com/enych/p/9233830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!