gpt4 book ai didi

javascript - 卡住了 "Expected an assignment or function: no-unused expressions"

转载 作者:行者123 更新时间:2023-11-28 17:01:30 25 4
gpt4 key购买 nike

我真的要疯了,希望有人能帮助我解决这个问题。我的模型中有以下代码:

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

但是奇怪的是,这仍然返回相同的警告。

有人能给我解释一下为什么会出现此警告以及我应该采取什么措施来解决此问题吗?我想要一个无警告的网络应用程序。

更新:我清理了我的代码,以便那些不参与该项目的人更容易理解。这是相互 react 的两种成分。对于从查询中获得的每个项目,我都会转到模型中的 fromJSON 方法。我将返回的值插入结果数组并返回该数组。

模型.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 : ''
}
}

服务.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 : '')
}
}

关于javascript - 卡住了 "Expected an assignment or function: no-unused expressions",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57306525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com