修复 options 中配置 visibleOn hiddenOn 不同步问题
This commit is contained in:
parent
6bd92a9356
commit
391d3f4aac
|
@ -26,7 +26,7 @@ title: 快速开始
|
|||
简单说明以上配置信息。
|
||||
|
||||
- `$schema` 这个字段可以忽略,他是指定当前 JSON 配置是符合指定路径 https://houtai.baidu.com/v2/schemas/page.json 的 JSON SCHEMA 文件描述的。PS: 编辑器就是靠这个描述文件提示的,可以 hover 到字段上看效果。
|
||||
- `type` 指定渲染器类型,这里指定的类型为 `page`。 更多渲染器类型可以去[这里面查看](./renderers)。
|
||||
- `type` 指定渲染器类型,这里指定的类型为 `page`。 更多渲染器类型可以去[这里面查看](./renderers.md)。
|
||||
- `title` 从 title 开始就是对应的渲染模型上的属性了。这里用来指定标题内容。
|
||||
- `subTitle` 副标题.
|
||||
- `remark` 标题上面的提示信息
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"index_name": "gh_pages",
|
||||
"start_urls": [
|
||||
"https://baidu.github.io/amis/#/docs/getting-started",
|
||||
"https://baidu.github.io/amis/#/docs/advanced",
|
||||
"https://baidu.github.io/amis/#/docs/renderers",
|
||||
"https://baidu.github.io/amis/#/docs/sdk",
|
||||
"https://baidu.github.io/amis/#/docs/dev",
|
||||
"https://baidu.github.io/amis/#/docs/style"
|
||||
],
|
||||
"js_render": true,
|
||||
"js_wait": 2,
|
||||
"use_anchors": true,
|
||||
"selectors": {
|
||||
"lvl0": ".markdown-body h1",
|
||||
"lvl1": ".markdown-body h2",
|
||||
"lvl2": ".markdown-body h3",
|
||||
"lvl3": ".markdown-body h4",
|
||||
"lvl4": ".markdown-body h5",
|
||||
"text": ".markdown-body p, .markdown-body li"
|
||||
},
|
||||
"min_indexed_level": 0,
|
||||
"nb_hits": 838
|
||||
}
|
|
@ -73,6 +73,7 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
this.handleToggle = this.handleToggle.bind(this);
|
||||
this.handleToggleAll = this.handleToggleAll.bind(this);
|
||||
this.setOptions = this.setOptions.bind(this);
|
||||
this.syncOptions = this.syncOptions.bind(this);
|
||||
this.setLoading = this.setLoading.bind(this);
|
||||
this.inputRef = this.inputRef.bind(this);
|
||||
this.reload = this.reload.bind(this);
|
||||
|
@ -167,7 +168,7 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
// todo 优化 name 变化情况。
|
||||
}
|
||||
|
||||
if (props.value !== nextProps.value) {
|
||||
if (props.value !== nextProps.value || formItem.expressionsInOptions) {
|
||||
formItem.syncOptions();
|
||||
}
|
||||
|
||||
|
@ -352,6 +353,11 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
formItem && formItem.setOptions(normalizeOptions(options || []));
|
||||
}
|
||||
|
||||
syncOptions() {
|
||||
const formItem = this.props.formItem as IFormItemStore;
|
||||
formItem && formItem.syncOptions();
|
||||
}
|
||||
|
||||
setLoading(value:boolean) {
|
||||
const formItem = this.props.formItem as IFormItemStore;
|
||||
formItem && formItem.setLoading(value);
|
||||
|
@ -374,6 +380,7 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
loading={formItem ? formItem.loading : false}
|
||||
setLoading={this.setLoading}
|
||||
setOptions={this.setOptions}
|
||||
syncOptions={this.syncOptions}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ export const FormItemStore = types
|
|||
joinValues: true,
|
||||
extractValue: false,
|
||||
options: types.optional(types.array(types.frozen()), []),
|
||||
expressionsInOptions: false,
|
||||
selectedOptions: types.optional(types.frozen(), []),
|
||||
filteredOptions: types.optional(types.frozen(), []),
|
||||
})
|
||||
|
@ -393,12 +394,18 @@ export const FormItemStore = types
|
|||
const value = self.value;
|
||||
const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item)
|
||||
: typeof value === 'string' ? value.split(self.delimiter || ',') : [value && value.hasOwnProperty(self.valueField || 'value') ? value[self.valueField || 'value'] : value];
|
||||
|
||||
let expressionsInOptions = false;
|
||||
let filteredOptions = self.options
|
||||
.filter((item:any) =>
|
||||
item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false
|
||||
: item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true
|
||||
: (item.visible !== false || item.hidden !== true)
|
||||
)
|
||||
.filter((item:any) => {
|
||||
if (!expressionsInOptions && (item.visibleOn || item.hiddenOn)) {
|
||||
expressionsInOptions = true;
|
||||
}
|
||||
|
||||
return item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false
|
||||
: item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true
|
||||
: (item.visible !== false || item.hidden !== true);
|
||||
})
|
||||
.map((item:any, index) => {
|
||||
|
||||
const disabled = evalExpression(item.disabledOn, form.data);
|
||||
|
@ -416,6 +423,7 @@ export const FormItemStore = types
|
|||
return newItem;
|
||||
});
|
||||
|
||||
self.expressionsInOptions = expressionsInOptions;
|
||||
const flattened:Array<any> = flattenTree(filteredOptions);
|
||||
const selectedOptions:Array<any> = [];
|
||||
|
||||
|
|
Loading…
Reference in New Issue