Skip to content

Instantly share code, notes, and snippets.

@kwbtdisk
Last active April 15, 2022 03:07
Show Gist options
  • Save kwbtdisk/774a7e6f10e6866ae5ccfa5a1a651548 to your computer and use it in GitHub Desktop.
Save kwbtdisk/774a7e6f10e6866ae5ccfa5a1a651548 to your computer and use it in GitHub Desktop.
CORE Framework 選択肢マスタ を活用する: ダイナミック多段選択肢を実現する https://youtu.be/U9ItZbuJMHg
/**
* ## 選択肢マスタ を活用する: ダイナミック多段選択肢を実現する
* - [ ] "勘定科目" カラムを作成: 通信費, 旅費交通費, 広告宣伝費, 接待交際費, 消耗品費
* - "種別" カラムの選択肢を "勘定科目" で選択された値に応じて表示する
* - 例: 勘定科目が "旅費交通費" の場合に、 "通勤" "出張交通費" "客先移動交通費"
* - カラム定義の Javascriptにて、
* - dynamicSelections: true
* - async selections() {...(ココでダイナミックにしたい) }
* - [x] 選択肢マスタを作成
* - グループ名: "旅費交通費:種別"
* - 値: "通勤" or "出張交通費" or "客先移動交通費"
* - "勘定科目:${勘定科目の値}:種別" グループ名の選択肢マスタを取得して、選択肢として利用できるようにする
* - async selections(row) の関数で、データを取得する
* - row.accoutingType の選択で、 "勘定科目:${row.accoutingType}:種別" というグループの選択肢マスタを取得してくる
* - const selections = await $core.$models.selectOptionsMaster.find({ filter: {group: `勘定科目:${row.accoutingType}:種別` } })
**/
{
dynamicSelections: true,
// selectionsの型: selections?(record: any, currentValue: any, initialValue: any, recordRoot: any, callerVueInstance: any): Promise<any[]> | any[]
async selections(row, currentValue, initialValue, recordRoot, callerVueInstance) {
if(!row.accoutingType) {
return ['']
}
// 選択肢を配列で返す
// データの状態 accoutingType によって選択肢マスタを取得して返却
const selections = await $core.$models.selectOptionsMaster.find({
filter: {
group: { _eq: `勘定科目:${row.accoutingType}:種別` }
}
})
console.log({selections})
debugger
return selections.map(sel => sel.value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment