- 相等比较
==: 只比较值,只要值相等就为true,会发生类型转换;
false=='0' //true
- 全等比较
=== :比较类型和值,都相等才为true,不发生类型转换,直接比较。
前台展示勾选框的时候,用到了checkbox,true为选中状态,false为取消状态。
<a-row class='label-row'>
<a-col :span="6" class='label-text-left'>
词根词性:
</a-col>
<a-col :span="18" style="padding-top:3px;">
<a-checkbox :disabled='item.noPass' style="margin-left:5px;" v-model="item.nounIdentification" @click="changeCheckBox(item,'nounIdentification')">名词</a-checkbox>
<a-checkbox :disabled='item.noPass' v-model="item.actionIdentification" @click="changeCheckBox(item,'actionIdentification')">动词</a-checkbox>
<a-checkbox :disabled='item.noPass' v-model="item.adjectiveIdentification" @click="changeCheckBox(item,'adjectiveIdentification')">形容词</a-checkbox>
<a-checkbox :disabled='item.noPass' v-model="item.otherIdentification" @click="changeCheckBox(item,'otherIdentification')">其他</a-checkbox>
</a-col>
</a-row>
后台保存的时候,要转数据格式,'0'代表选中,'1'代表未选中,详情接口返回的数据也是'0'或'1'。
那么前台就需要转成相应的数据。
- 展示转换:
watch: {
rootList:{
handler(val){
this.drawRootList = val;
for(let item of this.drawRootList){
item.cname = item.cname?item.cname:'';
item.nounIdentification = item.nounIdentification===true||item.nounIdentification==='0'?true:false;
item.actionIdentification = item.actionIdentification===true||item.actionIdentification==='0'?true:false;
item.adjectiveIdentification = item.adjectiveIdentification===true||item.adjectiveIdentification==='0'?true:false;
item.otherIdentification = item.otherIdentification===true||item.otherIdentification==='0'?true:false;
}
},
deep:true
}
},
- 保存转换
if(this.rootList&&this.rootList.length>0){
let arr = [];
for(let item of this.rootList){
let obj = {};
obj.ename = item.ename;
obj.cname = item.cname;
obj.nounIdentification = item.nounIdentification===true||item.nounIdentification==='0'?'0':'1';
obj.actionIdentification = item.actionIdentification===true||item.actionIdentification==='0'?'0':'1';
obj.adjectiveIdentification = item.adjectiveIdentification===true||item.adjectiveIdentification==='0'?'0':'1';
obj.otherIdentification = item.otherIdentification===true||item.otherIdentification==='0'?'0':'1';
obj.insideRootType = '1';
obj.rootType = '2';
obj.dataFieldId = this.tableInfo.dataFieldId;
obj.creator = _user.cname + "(" + _user.name + ")";
arr.push(obj);
}
eiInfo.set("rootList", arr);
}
如果用=='0',不用==='0',因为false=='0'也为true,那么保存的时候无论你是true还是false都会保存成'0'
obj.nounIdentification = item.nounIdentification===true||item.nounIdentification=='0'?'0':'1';
obj.actionIdentification = item.actionIdentification===true||item.actionIdentification=='0'?'0':'1';
obj.adjectiveIdentification = item.adjectiveIdentification===true||item.adjectiveIdentification=='0'?'0':'1';
obj.otherIdentification = item.otherIdentification===true||item.otherIdentification=='0'?'0':'1';
这也是稍不注意就会出现问题的一个小bug。
网友评论