跳转到内容

ModelSelect

模型选择

API

IModelSelectProps

参数类型说明默认值
conditionstring获取数据时的筛选条件-
createActionstring | boolean | function配置 ModelSelect控件的 新增 操作对应的 ViewAction, 值为 true 时使用对应模型的默认 Form 视图,值为函数时,直接调用-
createActionWithContextboolean新增时是否带上表单上下文-
dataSource(params: ILogicDataParams) => Promise<IDataSourceResult> | IDataSourceResult配置此字段后容器会通过dataSource获取数据,可用于mock或获取自定义数据-
modalTitlestring自定义控件的模态框标题-
extraFieldsstring配置需要额外获取的字段,“field1,field2,field3”, 如果要获取关联模型字段: “field4.field0”-
optionFormat(option: IDictionary) => string下拉选项可自定义,可用的字段默认包含mainField,其它字段通过extraFields 传入-
placeholderstring占位符-
dataParamsstring用法的数据容器有差异,必须使用表达式写法 :dataParams-
dataConditionstring用法的数据容器类似。dataCondition="" 表示使用空条件请求-
dataFlowstring使用此属性表示控件将从LogicFlow请求数据, dataFlow=“key”-
dataFunctionstring使用此属性表示控件将从LogicFunction请求数据,dataFunc=“key”-
dataFuncstring使用此属性表示控件将从LogicFunction请求数据,dataFunc=“key”-
muteboolean下拉/弹框时不请求数据-
selectFirstboolean是否默认选中第一项,需配合autoLoad使用-
autoLoadboolean说明: 是否自动加载数据,一般配合selectFirst(选中第一项)一起使用-
simpleValueModeboolean单值模式[id1,id2,id3]-
orderFieldstring用于排序的字段名-
order’desc’ | ‘asc’排序方式-
fuzzySearchableboolean隐藏模糊搜索框-
labelFieldstring显示的节点名称-
scrollscroll设置modelSelect popover里Table的滚动高度-
singleSelectboolean单选模式-
valueFieldstringvalue字段名称,组件将会从选中记录中提取该字段,作为回填值。‘id’

condition 条件筛选格式见: Condition 语法

用法

默认用法

<View title="ModelSelect" version="2">
<Record key="person" model="trantor_doc_Person" />
<Form model="trantor_doc_Department">
<Fields>
<!-- 获取额外参数,并在option中展示 -->
<Field name="staff" label="获取额外参数,格式化option">
<RenderType>
<ModelSelect
extraFields="age"
optionFormat="#{option => option.name + ', age:' + option.age}"
/>
</RenderType>
</Field>
<!-- 自定义选项的展示文本 -->
<Field name="staff" label="condition筛选">
<RenderType>
<ModelSelect condition="name=='李刚'"/>
</RenderType>
</Field>
<!-- 模态窗标题、配置 ModelSelect控件的 新增 操作对应的 ViewAction -->
<Field name="staff" label="标题+可新增">
<RenderType>
<ModelSelect modalTitle="自定义模态窗标题" createAction="#{true}"/>
</RenderType>
</Field>
<Field name="staff" label="指定展示字段">
<RenderType>
<ModelSelect model="trantor_doc_Person">
<Fields>
<Field name="name"/>
<Field name="age"/>
</Fields>
</ModelSelect>
</RenderType>
</Field>
</Fields>
</Form>
</View>

只使用下拉框简单简单交互(ModelSimpleSelect)

所有参数和 ModelSelect 一致,只是 RenderType 的名称换位 ModelSimpleSelect

<View title="人员列表" version="2">
<Table key="person" model="trantor_doc_Person" order="asc" orderField="age" dataCondition="">
<Search>
<Fields>
<Field name="name"/>
<Field label="部门名称" name="department" renderType="ModelSimpleSelect"/>
<Field name="staff" label="获取额外参数,格式化option">
<!-- 或者下面这种方式,可以传递更多参数 -->
<!-- <RenderType>
<ModelSimpleSelect
extraFields="age"
optionFormat="#{option => option.name + ', age:' + option.age}"
/>
</RenderType>
</Field> -->
</Fields>
</Search>
<!-- 配置列表展示字段 -->
<Fields>
<Field name="name"/>
<Field name="avatar"/>
<Field name="age"/>
<Field name="password"/>
<Field name="credentials"/>
<Field label="部门名称" name="department.name"/>
<Field name="birthday"/>
</Fields>
</Table>
</View>

指定展示字段

注意:当前例子为0.17.x 版本