選択したプルダウンを選んだ時に、対象の情報を取ってくる処理
Q&A
プルダウンで500000円以下、500000円以上-1000000円以下、1000000円以上2000000円以下、これが10000000円まであり、10000000円以上なら、10000000 円以上と表記のでるプルダウンがある。
選択したプルダウンの金額に応じて対象の商品を取ってくる処理を教えていただきたい。
angular➕Node.js、postgresを使用しています。
情報不足だと思うのでわからないことあれば質問いただけると幸いです。
html
<mat-select formControlName="amount" (selectionChange)="oSelectionChange($event)">
<mat-option value=""></mat-option>
<mat-option *ngFor="let option of amount" [value]="option.value">
{{ option.value | translate }}
template
public amountOptions: Option[];
server
if (body.amount?.length > 0) {
const conditions = [
{ amount: '<= :limit1', params: { limit1: 500000 } },
{
Amount: 'BETWEEN :minLimit2 AND :maxLimit2',
params: { minLimit2: 500000, maxLimit2: 1000000 },
},
conditions.forEach((condition, index) => {
const method = index === 0 ? 'andWhere' : 'orWhere';
query[method](`product.amount ${condition.amount}`, condition.params);
});
}