更新 PersistentVector 中的条目不工作 NEAR 协议
Updating an entry in PersistentVector not working NEAR Protocol
我正在尝试更新作业对象的状态。我收到“成功”消息 return,但该值未更新。我错过了什么吗?
@nearBindgen
export class Contract {
private jobs: PersistentVector<Job> = new PersistentVector<Job>('jobs');
......
@mutateState()
cancelJob(jobTitle: string): string {
for (let i = 0; i < this.jobs.length; i++) {
if (this.jobs[i].title == jobTitle) {
this.jobs[i].status = "Cancelled";
return "success"
}
}
return "not found";
}
我是这样称呼它的:
near call apptwo.msaudi.testnet cancelJob '{\"jobTitle\":\"title2\"}' --account-id=msaudi.testnet
获取条目时更新条目是不够的。您还需要更新合同上的存储。可以这么说。
这还不够
this.jobs[i].status = "Cancelled";
您需要将其重新添加到:
if (this.jobs[i].title == jobTitle) {
const job: Job = this.jobs[i]; // Need an intermediate object in memory
job.status = "Cancelled";
this.jobs.replace(i, job); // Update storage with the new job.
return "success"
}
我正在尝试更新作业对象的状态。我收到“成功”消息 return,但该值未更新。我错过了什么吗?
@nearBindgen
export class Contract {
private jobs: PersistentVector<Job> = new PersistentVector<Job>('jobs');
......
@mutateState()
cancelJob(jobTitle: string): string {
for (let i = 0; i < this.jobs.length; i++) {
if (this.jobs[i].title == jobTitle) {
this.jobs[i].status = "Cancelled";
return "success"
}
}
return "not found";
}
我是这样称呼它的:
near call apptwo.msaudi.testnet cancelJob '{\"jobTitle\":\"title2\"}' --account-id=msaudi.testnet
获取条目时更新条目是不够的。您还需要更新合同上的存储。可以这么说。
这还不够
this.jobs[i].status = "Cancelled";
您需要将其重新添加到:
if (this.jobs[i].title == jobTitle) {
const job: Job = this.jobs[i]; // Need an intermediate object in memory
job.status = "Cancelled";
this.jobs.replace(i, job); // Update storage with the new job.
return "success"
}