Outline
Mainly to solve the data dictionary drop-down box filled with data processing and data tables escape, a data dictionary can be used in several places.
1. Multiple pages of data using the same drop-down box, a place to change all the pages need to be modified
2. Data table instead of escaping to manually writetemplet
parsing templateData Dictionary provides a common approach to support configuration
静态数据字典
and动态数据字典
,, address data dictionary fileplugins/frame/js/fsDict.js
.
If you use数据字典
must belayui.js
introduced later in the data dictionary file/plugins/frame/js/fsDict.js
<script type="text/javascript" src="/plugins/frame/js/fsDict.js?v=1.4.0"></script>
Static Data Dictionary
Static data dictionary typically used for data that does not change, for example: Article status (active, inactive, publishing, auditing), user status (active, inactive, locked)
Instructions:
In layui.fsDict
the object, the definition of a data dictionary.
For example: static data dictionary definition of a city
- Configuration
城市
Data Dictionary Name:city
,city
is a json objects - Configuration
数据字典属性
layui.fsDict = {
//城市
city : {
formatType : "local", //local 静态数据字典
labelField : "name", //展示数据的属性
valueField : "code", //value对应的属性
//静态数据,数组
data:[{"code":"0","name":"北京","style":"color:#F00;"},
{"code":"1","name":"上海"},
{"code":"2","name":"广州"},
{"code":"3","name":"深圳"},
{"code":"4","name":"杭州"}
]
}
}
Escape reference data table data dictionary
Only in table columns, the configuration data dictionary information
dict="city"
<p field="city" title="城市" width="100" dict="city"/>
Data tables show a different style escape
If the table needs to show different information in different styles, in the datadata
, definestyle
, orcss
can be different styles to show different data in this way
Drop-down box reference data dictionary
We need to configure the css styles in selectclass="fsSelect"
and configure the dictionarydict="city"
<select name="city" lay-verify="required" lay-verType="tips" class="fsSelect" dict="city" addNull="1">
</select>
Dynamic Data Dictionary
Dynamic Data Dictionary using more scenarios, such as the type of cascading provinces will change.
Asynchronous request by the server to load the data list.
Instructions:
In layui.fsDict
the object, the definition of a data dictionary.
For example: static data dictionary definition of a city
- Configuration
省份
Data Dictionary Name:city
,city
is a json objects - Configuration
数据字典属性
layui.fsDict = {
//省份
area1 : {
formatType : "server", //server 动态数据字典
loadUrl : "/fsbus/1005", //异步加载数据的url地址
inputs : "parentid:0", //异步请求携带的参数
labelField : "name", //示数据的属性
valueField : "id" //value对应的属性
}
}
Escape reference data table data dictionary
Only in table columns, the configuration data dictionary information
dict="area1"
<p field="area1" title="省份" width="100" dict="area1"/>
Drop-down box reference data dictionary
We need to configure the css styles in selectclass="fsSelect"
and configure the dictionarydict="area1"
<select name="area1" class="fsSelect" dict="area1" addNull="1">
</select>
Static and dynamic dictionary Dictionary difference
There is no difference between static and dynamic dictionary Dictionary html use, the main difference is that fsDict.js
the configuration is not the same, the way to get data.
Dictionary configuration instructions
Attributes | Will lose | Defaults | name | description |
---|---|---|---|---|
formatType | Yes | Formatting way | server : Dynamic dictionary local : static dictionary |
|
loadUrl | no | Asynchronous loading url | Asynchronous loading of data url address | |
inputs | no | parameter | Asynchronous request carrying parameters | |
labelField | Yes | Display attribute data | Displaying information corresponding field | |
valueField | Yes | corresponding attribute value | the value of a corresponding field value | |
data | no | Static data array | Use static data dictionary | |
spaceMode | no | , | A plurality of display data delimiter | Data table used when escaping, a plurality of data delimiter |
- inputs and parameter Usage
If you are using fixed parameters, direct属性:值
, demo:parentid:0
, if multiple parameters can be,
split, demo:parentid:0,name:test
linkage table if you want to pass the currently selected value, directly属性:
, no need to write values, direct access to the currently selected default, demo:parentid:
.
If the value of the need to pass the other selectors can be configured属性:#选择器id
, for example:key:#area2222222
This article first appeared on my blog: ITCTO technology blog