创建form时带默认数据
作者:王书硕
场景
在新建”项目“时,选择了项目分类后点新建,所选择的分类会出现在表单的”项目分类“中。
- 选择分类
- 点新建
- 自动填写了“项目分类”
怎么实现
-
在跳转页面时,将需要的参数放入proxyHistory.push的第二个参数passParams中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class ProjectListPagePresenter extends QueryListPagePresenter< IProjectListPagePresenterOption >{ protected commandActionResolver(commandActions: ToolbarAction[]): ToolbarAction[] { commandActions.unshift({ id: 'project-view', group: ToolbarActionGroup.Group1, action: this.presenter.toolbarConnector.makeCreateButton({ onClick: billTypeId => { const hash = appRouterHashManager.generateHash(EN_Project, PageModeEnum.Form, { mode: BizFormModeEnum.Create, billTypeId: billTypeId, extraParams: { isBase: this.isBase, }, }); proxyHistory.push(hash, { onSuccess: this.presenter.refresh, category: this.category.curParent, }); }, }), }); return commandActions; } }
-
passParams中的数据会放到formPresenter的option中,取出使用即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
class ProjectFormPresenter extends EasyBizFormPresenter<IProject> { private options: IEasyBizFormPresenterOptions; constructor(options: IEasyBizFormPresenterOptions, private isBase?: boolean) { super(EN_Project, options); this.options = options; } @autobind protected onFormCreated(form: EntityForm<IProject>, disposers: Lambda[]) { // ... const stageGroup = form.select(F_Project_stageGroup); if (stageGroup && stageGroup.required) { form.select(F_Project_enableStage).value = true; } if (this.opotions.passParams.category) { form.select(F_Project_category).value = this.options.passParams.category; } if (this.bizFormPresenter.api.mode === 'Copy') { const clearFields = [ 'startDate', 'closedDate', 'changedReason', 'lastChangedTime', // ... } }