this.statues.shift();
正在隔离正确的元素并将其从数组中删除。但是,发生这种情况时,person.stoneed必须为false。有指针吗?谢谢。
代码:
class Medusa {
constructor(name) {
this.name = name;
this.statues = [];
}
stare(person) {
person.stoned = true;
this.statues.push(person);
if(this.statues.length > 3) {
this.statues.shift();
}
}
};
class Person {
constructor(name) {
this.name = name;
this.stoned = false;
}
};
答案 0 :(得分:1)
您需要保存移动的对象并设置其属性,如下所示:
if(this.statues.length > 3) {
const unstoned = this.statues.shift();
unstoned.stoned = false;
}
答案 1 :(得分:1)
由于对象是通过引用传递的,因此可以使用shift的返回值直接进行内联
<div class="pat-list">
<mat-selection-list [multiple]="false">
<mat-list-option *ngFor="let pat of patients" [value]="pat.patient_id" [routerLink]="['editDetails', pat.patient_id]" (click)="details(pat)">
<mat-icon mat-list-icon><img src="{{ pat.photo ? pat.photo : pat.gender == 'male' ? 'assets/images/personIcon.png' : 'assets/images/personIcon.png'}}" style="font-size: 20px;width: 50px; height: 50px;" /></mat-icon>
<div class="pat-text">
<div mat-line class="pat-name">{{pat.name}}</div>
<mat-icon matSuffix>keyboard_arrow_right</mat-icon>
</div>
<mat-divider></mat-divider>
</mat-list-option>
</mat-selection-list>
</div>
答案 2 :(得分:1)
$update = encomendas::join('encomendas', 'encomendas_detalhes.id_encomenda', '=', 'encomendas.id')
->join('users', 'encomendas_detalhes.id_user', '=', 'users.id')
->join('encomendas_pagamentos', 'encomendas.id', '=', 'encomendas_pagamentos.id_encomenda')
->where('encomendas_pagamentos.entidade', $ENTIDADE)
->where('encomendas_pagamentos.referencia', $REFERENCIA)
->where('encomendas_pagamentos.valor', $VALOR);
$update->estado = 2;
$update->save();
或
if(this.statues.length > 3) { this.statues[0].stoned=false; this.statues.shift(); }