到目前为止,值变了形状不变。真实画面不是这样 — 没人等和三个人等,得显示不同的东西。
分岔的地方
{ "type": "conditional", "condition": "{{empty}}",
"then": { "type": "text", "text": "Nobody is waiting", ... },
"orElse": { "type": "box", ... } }
为真走 then,为假走 orElse。两边都是普通节点,放什么都行。
这里用 {{empty}} 是要点。没有写成 {{waiting == 0}} 这样的表达式。决定条件的一方 是服务器,不是画面 — 「空」的定义一旦改变(比如决定预约不计入),要改的只有服务器。
不知数量的行
{ "type": "list", "items": "{{rows}}",
"itemTemplate": { "type": "linear", "direction": "horizontal", "distribution": "space-between",
"children": [
{ "type": "text", "text": "{{item.no}}", ... },
{ "type": "text", "text": "{{item.since}}", ... } ] } }
items 指向一个数组,itemTemplate 是 一行 的形状。有多少行,哪儿都没写。
模板里用 {{item.*}} 取这一行的值,不会和外面的状态串名。
{{rows}} 放三个就三行,放十个就十行。文件仍然是 1,234 字节。