js 把json字符串转为json对象


   <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 ////开启联动模式 } );

 

posted @ 2018-06-27 14:35  enych  阅读(567)  评论(0编辑  收藏  举报