当前位置:网站首页>Render values to corresponding text
Render values to corresponding text
2022-06-25 12:42:00 【fortunate_ leixin】
The value transferred from the edit page is value, Details page display value Corresponding text
demand : When selecting gender in the edit pop-up box There are three options male , Woman , A secret
Marital status can be married , unmarried , Whether to be on duty or not is optional , no , When it is transferred to the background, it corresponds to the transfer value, When the details are displayed, it shows value Corresponding Chinese characters . Because of the use of elementui-ui, I wrote all the information in one el-row in , Directly traverse an array of objects . Then it involves the echo of the value , This is what I do :1 Define an array of objects , Every object in the array has key,value attribute ,key Is the field displayed on the page ,value Is the field name of the entity class used , If the field is gender , yes 1,2 Such figures are used to judge men and women , It is in this object that an identity is being defined , Such as other, Set to ture, You need to write the male and female corresponding to the returned value , Such as the gender returned in the background ,1 For men ,2 For women , That's the definition : { name: ‘ Gender ’, value: ‘gender’, other: true, ‘1’: ‘ male ’, ‘2’: ‘ Woman ’, ‘3’: ‘ A secret ’ };2: Define an object , To receive the information returned from the background ;3: Traverse . Record the specific implementation
Effect display :
Detail display
Edit the pop-up :
Concrete realization :
userInfo: [
{ name: ' Gender ', value: 'gender', other: true, '1': ' male ', '2': ' Woman ', '3': ' A secret ' },,
{ name: ' Marital status ', value: 'maritalStatus', other: true, '1': ' married ', '2': ' unmarried ' },
{ name: ' On duty or not ', value: 'isAttendance', other: true, '1': ' yes ', '2': ' no ' },
],
// Entities returned in the background , It's an object , Here, the attributes of the object should be the same as userInfo Of each object in value One-to-one correspondence
inf: {
gender: '',
maritalStatus: '',
isAttendance: '',
},
// Request background interface
getBasicInfoByUserId(this.inf.userId).then(response => {
if (response.code === 200) {
// assignment
this.inf = response.data
}
})
// Data rendering
<div style="font-size: 14px;color: #27314a; line-height: 32px;">
<el-row :gutter="10">
<el-col v-for="(item,index) in userInfo" :key="index" :span="12">
// Here we use signs to judge
{
{ item.name }}:{
{ item.other?item[inf[item.value]]:inf[item.value] }}
</el-col>
</el-row>
</div>
// Or define a formatter Method
<div style="font-size: 14px;color: #27314a; line-height: 32px;">
<el-row :gutter="10">
<el-col v-for="(item,index) in userInfo" :key="index" :span="12">
{
{ item.name }}:{
{formatters(item) }}
</el-col>
</el-row>
</div>
mthoods in
methods: {
// Format display data
formatters(item) {
console.log(item)
if (item.other !== undefined && item.other != null) {
return item[this.inf[item.value]]
} else {
return this.inf[item.value]
}
}
边栏推荐
- Go novice exploration pause
- Draw the satellite sky map according to the azimuth and elevation of the satellite (QT Implementation)
- Execution order of MySQL query statements join, on and where
- Ramda rejects objects with null and empty object values in the data
- Error while sending STMT_ PREPARE packet. PID=29294
- VIM common commands and shortcut keys
- 地理空间搜索 ->R树索引
- ECSHOP commodity page multi-attribute batch purchase plug-ins ECSHOP wholesale plug-ins multi-attribute order placing, multi-attribute batch purchase of commodities
- Negative sample image used in yolov5 training
- 地理空间搜索:kd树的实现原理
猜你喜欢

聊聊高可用的 11 个关键技巧

Happy shopkeeper source code -- Introduction to happy shopkeeper system development mode

Optimal solution for cold start

Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation

(4) Pyqt5 tutorial -- > Custom signal and slot (super winding...)

Guess Tongyuan B

高性能负载均衡架构如何实现?

Laravel excel export

Singleton mode in PHP to reduce memory consumption

Idea2017 how to set not to automatically open a project at startup
随机推荐
flutter 收到推送后自动消失问题
Qt5 multi thread operation implemented by object base class and use of movetothread method
JS array length is defined
The difference between this and super and their respective functions
Learning notes 2022 overview | automatic graph machine learning, describing AGML methods, libraries and directions
按权重随机选择[前缀和+二分+随机target]
Pycaret successfully resolved the problem that 'sklearn model_ selection._ Search 'import name "\u check\u param\u grid"
The server reported an error 503 service unavailable:the system returned: (71) protocol error
Ten commandments of self-learning in machine learning
Does sklearex make your sklearn machine learning model training fly fast?
Some fields are ignored in tp6 query
Select randomly by weight [prefix and + dichotomy + random target]
Negative sample image used in yolov5 training
el-select clear 清空内容时触发事件
Installation and removal of MySQL under Windows
PHP parsing QR code content
Development with courtesy -- share the source code of the secondary development of the app system of the imitation shopping mall
PHP replaces the key of a two-dimensional array with a specified element value
Thinkphp3 reinforcement i() function filter single quotation marks
The whole page turns gray