## JSON字段存储
- 实现表单组合并到指定的字段中,并以JSON格式存储
- 表单模式:JSON指定模式和field指定模式
#### 示例效果:路径/ht/json
![](/static/plugins/tphp/backstage/example/list_json/menu.png)
数据设置
```
<?php
return [
'type' => 'sql',
'method' => 'list',
'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表
![](/static/plugins/tphp/backstage/example/list_json/table.png)
点击:后台模块 > JSON存储
![](/static/plugins/tphp/backstage/example/list_json/demo.gif)
编辑截图
![](/static/plugins/tphp/backstage/example/list_json/edit.png)
- json表数据
![](/static/plugins/tphp/backstage/example/list_json/table2.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"}