## JSON字段存储 - 实现表单组合并到指定的字段中,并以JSON格式存储 - 表单模式:JSON指定模式和field指定模式 #### 示例效果:路径/ht/json ![](https://img.kancloud.cn/49/57/49575142232365754a8636d0ba84de2b_498x192.png) 数据设置 ~~~ <?php return [ 'type' => 'sql', 'config' => [ 'table' => 'json' ], ]; ~~~ 列表设置 ~~~ <?php return [ 'field' => [ 'id' => [ 'width' => 150, 'fixed' => true ], 'data_1' => ['width' => 50], 'data_2' => ['width' => 50] ], 'handle' => [ 'hobby' => [ 'name' => '兴趣爱好', 'type' => 'selects', 'from' => [ 'hobby', 'id', 'name' ], 'json' => 'data_1', // JSON数据保存到字段data_1中,键为hobby ], 'email' => [ 'name' => '邮箱', 'json' => 'data_1', ], 'mobile' => [ 'name' => '手机号', 'json' => 'data_1', ], 'dream' => [ 'name' => '梦想', 'type' => 'radio', 'list' => [ 'a' => '科学家', 'b' => '发明家', 'c' => '程序员', ], 'json' => 'data_1', ], 'data_2' => [ 'type' => 'field', // 字段类型,把key-value保存到data_2字段中,并以JSON数据格式存储 'field' => [ 'name' => '昵称', 'star' => '偶像', 'music' => '歌曲' ] ] ], 'handleinfo' => [ 'ismax' => true ], 'is' => [ 'add' => true, 'delete' => true ] ]; ~~~ #### 数据库设置 - json表 ![](https://img.kancloud.cn/a6/92/a69263bc558a4ec99d0b54efc2af5b22_940x98.png) 点击:后台模块 > JSON存储 ![](https://img.kancloud.cn/f3/7e/f37eae2a4612355fad91f687d243bffe_956x550.gif) 编辑截图 ![](https://img.kancloud.cn/92/89/9289a67f9fa552de79fd478c4ee3c194_752x438.png) - json表数据 ![](https://img.kancloud.cn/9a/60/9a60faf823e02dd8dfb79f421664051a_630x67.png) data_1:{"hobby":"1,2,5","email":"336296@qq.com","mobile":"19865336296","dream":"c"} data_2:{"name":"\u661f\u5c0f\u70e6","star":"\u5218\u5fb7\u534e","music":"\u591c\u7a7a\u4e2d\u6700\u4eae\u7684\u661f"}