mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-24 13:44:54 +00:00
Update data binding resolution context
This commit is contained in:
@@ -26,7 +26,7 @@ export function JSONUIRenderer({
|
||||
}
|
||||
|
||||
if (component.loop) {
|
||||
const items = resolveDataBinding(component.loop.source, dataMap) || []
|
||||
const items = resolveDataBinding(component.loop.source, dataMap, context) || []
|
||||
return (
|
||||
<>
|
||||
{items.map((item: any, index: number) => {
|
||||
@@ -59,7 +59,7 @@ export function JSONUIRenderer({
|
||||
const props: Record<string, any> = { ...component.props }
|
||||
|
||||
if (component.dataBinding) {
|
||||
const boundData = resolveDataBinding(component.dataBinding, dataMap)
|
||||
const boundData = resolveDataBinding(component.dataBinding, dataMap, context)
|
||||
if (boundData !== undefined) {
|
||||
props.value = boundData
|
||||
props.data = boundData
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
export function resolveDataBinding(binding: string | { source: string; path?: string }, dataMap: Record<string, any>): any {
|
||||
export function resolveDataBinding(
|
||||
binding: string | { source: string; path?: string; transform?: string },
|
||||
dataMap: Record<string, any>,
|
||||
context: Record<string, any> = {},
|
||||
): any {
|
||||
const mergedContext = { ...dataMap, ...context }
|
||||
|
||||
if (typeof binding === 'string') {
|
||||
return dataMap[binding]
|
||||
if (binding.includes('.')) {
|
||||
return getNestedValue(mergedContext, binding)
|
||||
}
|
||||
return mergedContext[binding]
|
||||
}
|
||||
|
||||
const { source, path } = binding
|
||||
const data = dataMap[source]
|
||||
|
||||
if (!path) return data
|
||||
|
||||
return getNestedValue(data, path)
|
||||
const { source, path, transform } = binding
|
||||
const data = mergedContext[source]
|
||||
const resolvedValue = path ? getNestedValue(data, path) : data
|
||||
|
||||
return transform ? transformData(resolvedValue, transform) : resolvedValue
|
||||
}
|
||||
|
||||
export function getNestedValue(obj: any, path: string): any {
|
||||
|
||||
Reference in New Issue
Block a user