修改$refs->$ref

This commit is contained in:
catchonme 2019-06-21 17:31:45 +08:00
parent 4b05a27239
commit 2e6ae1fc53
4 changed files with 32 additions and 32 deletions

View File

@ -127,7 +127,7 @@ test('factory:definitions', () => {
type: 'text',
name: 'jack',
value: 'refs value',
remark: '通过<code>\\$refs</code>引入的组件'
remark: '通过<code>\\$ref</code>引入的组件'
},
bb: {
type: 'combo',
@ -143,12 +143,12 @@ test('factory:definitions', () => {
{
label: 'combo 2',
name: 'value',
$refs: 'aa'
$ref: 'aa'
},
{
name: 'children',
label: 'children',
$refs: 'bb'
$ref: 'bb'
}
]
}
@ -163,12 +163,12 @@ test('factory:definitions', () => {
controls: [
{
label: 'text2',
$refs: 'aa',
$ref: 'aa',
name: 'refs1'
},
{
label: 'combo',
$refs: 'bb',
$ref: 'bb',
name: 'refs2'
}
]
@ -190,7 +190,7 @@ test('factory:definitions override', () => {
aa: {
type: 'text',
name: 'jack',
remark: '通过<code>\\$refs</code>引入的组件'
remark: '通过<code>\\$ref</code>引入的组件'
},
bb: {
type: 'combo',
@ -206,12 +206,12 @@ test('factory:definitions override', () => {
{
label: 'combo 2',
name: 'value',
$refs: 'aa'
$ref: 'aa'
},
{
name: 'children',
label: 'children',
$refs: 'bb'
$ref: 'bb'
}
]
}
@ -226,12 +226,12 @@ test('factory:definitions override', () => {
controls: [
{
label: 'text2',
$refs: 'aa',
$ref: 'aa',
name: 'refs1'
},
{
label: 'combo',
$refs: 'bb',
$ref: 'bb',
name: 'refs2',
type: 'checkboxes',
value: 1,

View File

@ -1,6 +1,6 @@
## Definitions
`Definitions`建立当前页面公共的配置项,在其他组件中可以通过`$refs`来引用当前配置项中的内容
`Definitions`建立当前页面公共的配置项,在其他组件中可以通过`$ref`来引用当前配置项中的内容
```schema:height="600"
{
@ -9,7 +9,7 @@
"type": "text",
"name": "jack",
"value": "refs value",
"remark": "通过<code>\\$refs</code>引入的组件"
"remark": "通过<code>\\$ref</code>引入的组件"
},
"bb": {
"type": "combo",
@ -25,13 +25,13 @@
{
"label": "combo 2",
"name": "value",
"$refs": "aa",
"$ref": "aa",
"remark": "<code>definitions</code> 中可以引用 <code>definitions</code> 中其他的属性"
},
{
"name": "children",
"label": "children",
"$refs": "bb"
"$ref": "bb"
}
]
}
@ -46,12 +46,12 @@
"controls": [
{
"label": "text2",
"$refs": "aa",
"$ref": "aa",
"name": "refs1"
},
{
"label": "combo",
"$refs": "bb",
"$ref": "bb",
"name": "refs2"
}
]
@ -63,7 +63,7 @@
"controls": [
{
"label": "select",
"$refs": "aa",
"$ref": "aa",
"name": "select",
"type": "select",
"value": 1,
@ -81,7 +81,7 @@
},
{
"label": "radios",
"$refs": "bb",
"$ref": "bb",
"type": "radios",
"name": "radios",
"value": "Option A",

View File

@ -5,7 +5,7 @@ export default {
type: 'text',
name: 'jack',
value: 'refs value',
remark: '通过<code>\\$refs</code>引入的组件'
remark: '通过<code>\\$ref</code>引入的组件'
},
bb: {
type: 'combo',
@ -21,13 +21,13 @@ export default {
{
label: 'combo 2',
name: 'value',
$refs: 'aa',
$ref: 'aa',
remark: '<code>definitions</code> 中可以引用 <code>definitions</code> 中其他的属性'
},
{
name: 'children',
label: 'children',
$refs: 'bb'
$ref: 'bb'
}
]
}
@ -42,12 +42,12 @@ export default {
controls: [
{
label: 'text2',
$refs: 'aa',
$ref: 'aa',
name: 'refs1'
},
{
label: 'combo',
$refs: 'bb',
$ref: 'bb',
name: 'refs2'
}
]
@ -59,7 +59,7 @@ export default {
controls: [
{
label: 'select',
$refs: 'aa',
$ref: 'aa',
name: 'select',
type: 'select',
value: 1,
@ -77,7 +77,7 @@ export default {
},
{
label: 'radios',
$refs: 'bb',
$ref: 'bb',
type: 'radios',
name: 'radios',
value: 'Option A',

View File

@ -412,21 +412,21 @@ class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
let schema = props.schema;
let path = props.$path;
const rendererResolver = props.env.rendererResolver || resolveRenderer;
if (schema.$refs) {
if (schema.$ref) {
schema = {
...props.resolveDefinitions(schema.$refs),
...props.resolveDefinitions(schema.$ref),
...schema
};
delete schema.$refs;
delete schema.$ref;
path = path.replace(/(?!.*\/).*/, schema.type);
}
// value 会提前从 control 中获取到所有需要把control中的属性也补充完整
if (schema.control && schema.control.$refs) {
if (schema.control && schema.control.$ref) {
schema.control = {
...props.resolveDefinitions(schema.control.$refs),
...props.resolveDefinitions(schema.control.$ref),
...schema.control
}
delete schema.control.$refs;
delete schema.control.$ref;
}
this.renderer = rendererResolver(path, schema, props);
return schema;
@ -477,7 +477,7 @@ class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
...rest
} = this.props;
if (schema.$refs) {
if (schema.$ref) {
schema = this.resolveRenderer(this.props);
}