在后端,无论模型如何保存,更新或重新排序,我都需要导出数据文件。除了重新排序(拖放功能,也称为“重新排序”行为)之外,以下功能可以正常工作。谁能提出解决重新订购问题的方法?
// after the model is saved, either created or updated.
public function afterSave()
{
// export data here or fire the my export event
}
答案 0 :(得分:1)
嗯,似乎有一种特质正在做subprojects {
project.configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
details.useVersion "0.55.4" // Your real React Native version here
}
}
force 'com.facebook.android:facebook-android-sdk:4.22.1'
}
}
}
及其位于sorting and saving
的位置,已将其添加到模型中以使其可排序。
vendor\october\rain\src\Database\Traits\Sortable.php
此方法在/**
* Sets the sort order of records to the specified orders. If the orders is
* undefined, the record identifier is used.
* @param mixed $itemIds
* @param array $itemOrders
* @return void
*/
public function setSortableOrder($itemIds, $itemOrders = null)
{
if (!is_array($itemIds)) {
$itemIds = [$itemIds];
}
if ($itemOrders === null) {
$itemOrders = $itemIds;
}
if (count($itemIds) != count($itemOrders)) {
throw new Exception('Invalid setSortableOrder call - count of itemIds do not match count of itemOrders');
}
foreach ($itemIds as $index => $id) {
$order = $itemOrders[$index];
$this->newQuery()->where($this->getKeyName(), $id)->update([$this->getSortOrderColumn() => $order]);
// =======================================
// YOUR EXPORT CODE CAN BE HERE
// =======================================
}
}
时被调用,因此可能只是sorting happens
和copy this method code in your model
在此方法中写入override default behavior
,并且每次{{1} }
到目前为止,我猜这是我发现的最简单的逻辑。
如有疑问,请发表评论。