Skip to content

list 从不渲染 children,且全仓不存在 item / index 迭代作用域 —— schema-expressions.md 的「Iteration scopes」整节是空头支票 #4797

Description

@yinlianghui

发现于 #4786 的实施,真实 SchemaRenderer 探针实测。

教学面的承诺

skills/objectui/guides/schema-expressions.md 的 "Iteration scopes (loops)" 一节写着:

Components like Grid, List, and Table inject scoped variables for each item
... Inside the loop body, item refers to the current element and index to its 0-based position.

并给出 { "type": "list", "bind": "users", "children": [ { "type": "card", ... "${item.name}" } ] }

实测:两条都不成立

@@PROBE list/children-toplevel text="" ({type:'list',bind:'users',children:[{type:'text',content:'X'}]}, users=2 条)
@@PROBE list/items-as-nodes text="AdaLinus" ({type:'list',items:[{content:'Ada'},{content:'Linus'}]})

第一行:绑定了 2 条数据,渲染出 2 个li,children 一次都没进去。

成因(读码)

packages/components/src/renderers/data-display/list.tsx 的 render body:

{items.map((item: any,index: number)=>(<likey={index}className={cn(typeofitem==='object'&&item.className)}>{typeofitem==='string' ? item : item.content||renderChildren(item.body)}</li>))}

它把绑定到的数据条目本身当作 schema 节点渲染(读 item.content / item.body),完全不看 schema.children。所以 list 是"数据即节点"的形态,不是"模板 + 迭代"的形态。

item / index 作用域:ExpressionEvaluatorpackages/react/src/SchemaRenderer.tsx 里的 scope 是 { ...predicateScope, current_user, data: dataSource, page: pageVariables } —— 没有 item,也没有 index。全仓 grep 不到任何往求值作用域注入 item: / index: 的地方。

为什么 #4786 没有顺手改

#4786 的范围是拆 props 信封。这一节的示例确实带信封,但信封不是它的病根:把 title 提到节点上,${item.name} 既不会被求值(#4795)、children 也根本不会被渲染 —— 改完会变成一个"看起来修好了、其实照样空白"的示例,比原样更难被发现。故 #4786 的 PR 刻意保留了这一处信封原样,并在其甄别表里指向本单。

修法方向(需裁决)

  1. 实现迭代:给 list(以及 prose 里点名的 Grid / Table)加真正的模板迭代 + item/index 作用域注入。这是新能力,不是修 bug。
  2. 收缩文档:删掉「Iteration scopes」整节,改为如实描述 list 的"数据即节点"形态。

哪条都不该由实施 agent 自己猜 —— prose 承诺的是能力 1,代码实现的是形态 2。

参考

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions