求教各位,這樣的if嵌套怎么優化??
if (this.editedIndex === -1) {
this.isParentNode = true;
this.editable = false;
} else {
if (item.pid === 0) {
this.isParentNode = true;
} else {
this.isParentNode = false;
this.editable = false;
}
}
uj5u.com熱心網友回復:
this.isParentNode = this.editedIndex === -1 || item.pid === 0 ? true : false;this.editable = this.editedIndex === -1 || item.pid !== 0 ? false : this.editable;
uj5u.com熱心網友回復:
isParentNode = (this.editedIndex != -1 && item.pid != 0)? false :trueuj5u.com熱心網友回復:
簡化不能把變數賦值給丟了呀........uj5u.com熱心網友回復:
確實,少了this.editable變數了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/244506.html
標籤:JavaScript
上一篇:抓包結果怎么回事
