卡在 "Expected an assignment or function: no-unused expressions"
Stuck with the "Expected an assignment or function: no-unused expressions"
我真的快疯了,希望有人能帮我解决这个问题。
我的模型中有以下代码:
this.text = json.text ? json.text : ''
这会在我的检查器中发送以下警告
Expected an assignment or function call and instead saw an expression no-unused-expressions
所以我尝试了以下方法:
let text;
if(json.text) text = json.text
else text = ''
this.text = text
但是,奇怪的是,这仍然是 return 相同的警告。
有人可以解释为什么会出现此警告以及我应该如何解决这个问题吗?我想要一个没有警告的网络应用程序。
更新:
我清理了我的代码,让那些不在项目中的人更容易理解它。
这是相互反应的两个成分。
对于从查询中获得的每个项目,我转到模型中的 fromJSON 方法。我将 returned 值推入我的结果数组和 return 该数组。
Model.js
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis
this.postal
this.text
this.type
}
fromJSON(json) {
this.nis = json.nisCode ? json.nisCode : ''
this.postal = json.postal ? json.postal : ''
this.text = json.text ? json.text : ''
this.type = json.type ? json.type : ''
}
}
Service.js
import { BaseService } from './BaseService';
import Model from '../models/Model';
import Translation from '../components/_translations/Meta';
// To get content in correct language
const lang = new Translation().getContent('lang')
export default class Service extends Service {
async search(keyword, type = 'keyword', query) {
// Get the results data using the Axios instance
return this.axiosInstanceOsn.get(query).then(
value => {
// First and foremost, check if the call was successful
if (value.status === 200){
const data = value.data
let results = []
data.forEach(element => {
let as = new Model()
as.fromJSON(element)
results.push(as)
})
return results
}
}
)
}
}
已更新 2
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis = ''
this.postal = ''
this.text = ''
this.type = ''
}
fromJSON(json) {
this.nis = (json.nisCode !== undefined ? json.nisCode : '')
this.postal = (json.postal !== undefined ? json.postal : '')
this.text = (json.text !== undefined ? json.text : '')
this.type = (json.type,!== undefined ? json.type : '')
}
}
试试这个
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis = this.nis || ''
this.postal = this.postal || ''
this.text = this.test || ''
this.type = this.type || ''
}
我真的快疯了,希望有人能帮我解决这个问题。 我的模型中有以下代码:
this.text = json.text ? json.text : ''
这会在我的检查器中发送以下警告
Expected an assignment or function call and instead saw an expression no-unused-expressions
所以我尝试了以下方法:
let text;
if(json.text) text = json.text
else text = ''
this.text = text
但是,奇怪的是,这仍然是 return 相同的警告。
有人可以解释为什么会出现此警告以及我应该如何解决这个问题吗?我想要一个没有警告的网络应用程序。
更新: 我清理了我的代码,让那些不在项目中的人更容易理解它。 这是相互反应的两个成分。 对于从查询中获得的每个项目,我转到模型中的 fromJSON 方法。我将 returned 值推入我的结果数组和 return 该数组。
Model.js
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis
this.postal
this.text
this.type
}
fromJSON(json) {
this.nis = json.nisCode ? json.nisCode : ''
this.postal = json.postal ? json.postal : ''
this.text = json.text ? json.text : ''
this.type = json.type ? json.type : ''
}
}
Service.js
import { BaseService } from './BaseService';
import Model from '../models/Model';
import Translation from '../components/_translations/Meta';
// To get content in correct language
const lang = new Translation().getContent('lang')
export default class Service extends Service {
async search(keyword, type = 'keyword', query) {
// Get the results data using the Axios instance
return this.axiosInstanceOsn.get(query).then(
value => {
// First and foremost, check if the call was successful
if (value.status === 200){
const data = value.data
let results = []
data.forEach(element => {
let as = new Model()
as.fromJSON(element)
results.push(as)
})
return results
}
}
)
}
}
已更新 2
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis = ''
this.postal = ''
this.text = ''
this.type = ''
}
fromJSON(json) {
this.nis = (json.nisCode !== undefined ? json.nisCode : '')
this.postal = (json.postal !== undefined ? json.postal : '')
this.text = (json.text !== undefined ? json.text : '')
this.type = (json.type,!== undefined ? json.type : '')
}
}
试试这个
import BaseModel from './BaseModel'
export default class Model extends BaseModel {
constructor(){
super()
this.nis = this.nis || ''
this.postal = this.postal || ''
this.text = this.test || ''
this.type = this.type || ''
}