Last active
November 1, 2021 01:22
-
-
Save kwbtdisk/de1ec58d117ba8633253e14092c86216 to your computer and use it in GitHub Desktop.
https://youtu.be/XVo5bcTLHYI CORE リレーションカラムの選択値を活用して他のフィールドを更新する リレーションシップ + editCallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* "データタイプ" で M2Oリレーションシップ を選択し、 | |
* リレーションデータのラベル表示 (Label formatter) 欄へ下記を入力 | |
**/ | |
return row.name + ` (¥${row.price})` | |
/** | |
* JS形式の追加カラム定義 (otherColAttributes) へ設定 | |
* | |
* ## CORE リレーションカラムの選択値を活用して他のフィールドを更新する (リレーションシップ + editCallback) | |
* - リレーションカラム "商品 (product)" を選択したときに、その商品価格を自動で "金額 (amount)" を登録したい | |
* - editCallback 関数を定義する | |
* - 選択された値 (newValue): products モデルの id にてデータを取得 | |
* - データの "金額 (amount)" を更新する | |
*/ | |
{ | |
async editCallback ({row, newValue, oldValue}) { | |
// row のプロパティを書き換えることで、現在入力しているデータを変更する | |
if(newValue !== oldValue && newValue) { | |
// 選択された値 (newValue): products モデルの id | |
// にてデータを取得 | |
// $core.$models.products を利用 | |
const productData = await $core.$models.products.findById(newValue) | |
console.log(productData) | |
debugger | |
row.amount = productData.price | |
} | |
return row | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment