Combo item 支持获取 index
This commit is contained in:
parent
6162fc9096
commit
d658b03668
|
@ -238,17 +238,17 @@ const navigations = [
|
|||
component: makeSchemaRenderer(FormulaFormSchema)
|
||||
},
|
||||
|
||||
{
|
||||
label: '布局测试',
|
||||
path: 'form/layout-test',
|
||||
component: makeSchemaRenderer(FormLayoutTestSchema)
|
||||
},
|
||||
// {
|
||||
// label: '布局测试',
|
||||
// path: 'form/layout-test',
|
||||
// component: makeSchemaRenderer(FormLayoutTestSchema)
|
||||
// },
|
||||
|
||||
{
|
||||
label: '测试',
|
||||
path: 'form/test',
|
||||
component: makeSchemaRenderer(TestFormSchema)
|
||||
},
|
||||
// {
|
||||
// label: '测试',
|
||||
// path: 'form/test',
|
||||
// component: makeSchemaRenderer(TestFormSchema)
|
||||
// },
|
||||
]
|
||||
},
|
||||
|
||||
|
|
|
@ -332,7 +332,48 @@ export default {
|
|||
name: "combo888",
|
||||
label: "当前值",
|
||||
tpl: "<pre>${combo888|json}</pre>"
|
||||
}, {
|
||||
type: 'divider'
|
||||
},
|
||||
|
||||
{
|
||||
type: "hidden",
|
||||
name: "a_super",
|
||||
value: "123"
|
||||
},
|
||||
|
||||
{
|
||||
type: "combo",
|
||||
name: "combo999",
|
||||
label: "可获取父级数据",
|
||||
multiple: true,
|
||||
canAccessSuperData: true,
|
||||
controls: [
|
||||
{
|
||||
name: "a_super",
|
||||
type: "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
type: "combo",
|
||||
name: "combo9999",
|
||||
label: "显示序号",
|
||||
multiple: true,
|
||||
controls: [
|
||||
{
|
||||
type: "tpl",
|
||||
tpl: "<%= data.index + 1%>",
|
||||
className: "p-t-xs",
|
||||
mode: "inline"
|
||||
},
|
||||
{
|
||||
name: "a",
|
||||
type: "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -571,7 +571,10 @@ export function HocStoreFactory(renderer:{
|
|||
} else {
|
||||
store.initData(createObject(nextProps.scope, nextProps.data));
|
||||
}
|
||||
} else if (nextProps.scope !== props.scope) {
|
||||
} else if (nextProps.data && nextProps.data.__super) {
|
||||
(!props.data || nextProps.data.__super !== props.data.__super)
|
||||
&& store.initData(createObject(nextProps.data.__super, store.data));
|
||||
} else if (nextProps.scope !== props.scope) {
|
||||
store.initData(createObject(nextProps.scope, store.data));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ export interface ComboProps extends FormControlProps {
|
|||
removable?: boolean;
|
||||
deleteApi?: Api,
|
||||
deleteConfirmText?: string;
|
||||
canAccessSuperData?: boolean;
|
||||
subFormMode?: 'normal' | 'inline' | 'horizontal';
|
||||
noBorder?: boolean;
|
||||
joinValues?: boolean;
|
||||
|
@ -358,18 +359,23 @@ export default class ComboControl extends React.Component<ComboProps> {
|
|||
}
|
||||
}
|
||||
|
||||
formatValue(value:any) {
|
||||
formatValue(value:any, index:number) {
|
||||
const {
|
||||
flat
|
||||
flat,
|
||||
data,
|
||||
canAccessSuperData
|
||||
} = this.props;
|
||||
|
||||
if (flat) {
|
||||
return {
|
||||
value = {
|
||||
flat: value
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return value;
|
||||
value = value || this.defaultValue;
|
||||
return canAccessSuperData
|
||||
? createObject(createObject(data, {index, __index: index}), value)
|
||||
: createObject({index, __index: index}, value);
|
||||
}
|
||||
|
||||
renderMultipe() {
|
||||
|
@ -460,7 +466,7 @@ export default class ComboControl extends React.Component<ComboProps> {
|
|||
className={cx(`Combo-item`)}
|
||||
key={this.keys[index] || (this.keys[index] = guid())}>
|
||||
<div className={cx(`Combo-itemInner`)}>
|
||||
{render('multiple', {
|
||||
{render(`multiple/${index}`, {
|
||||
type: 'form',
|
||||
controls: finnalControls,
|
||||
wrapperComponent: 'div',
|
||||
|
@ -470,7 +476,7 @@ export default class ComboControl extends React.Component<ComboProps> {
|
|||
}, {
|
||||
index,
|
||||
disabled,
|
||||
data: this.formatValue(value) || this.defaultValue,
|
||||
data: this.formatValue(value, index),
|
||||
onChange: this.handleChange.bind(this, index),
|
||||
onAction: this.handleAction,
|
||||
ref: (ref:any) => this.formRef(ref, index),
|
||||
|
|
|
@ -723,7 +723,7 @@ export default class Form extends React.Component<FormProps, object> {
|
|||
|
||||
return (
|
||||
<div className={`${ns}Form-row`}>
|
||||
{controls.map((control, key) => ~['hidden', 'formula'].indexOf((control as any).type) ? this.renderControl(control, key, otherProps) : (
|
||||
{controls.map((control, key) => ~['hidden', 'formula'].indexOf((control as any).type) || (control as any).mode === "inline" ? this.renderControl(control, key, otherProps) : (
|
||||
<div key={key} className={cx(`${ns}Form-col`, (control as Schema).columnClassName)}>
|
||||
{this.renderControl(control, '', {
|
||||
...otherProps,
|
||||
|
|
Loading…
Reference in New Issue