我有这段代码:
REBOL [Title: "Employee list"]
screen1: does [
emp-list: [
"Amy" 1
"Bob" 2
"Carrie" 3
]
gui-layout: [ text "click your name" ]
foreach [emp-name emp-id] emp-list [
append gui-layout compose/deep [
box (emp-name) [screen2 (emp-id)]
]
]
view layout gui-layout
]
screen2: func [emp-id] [
choice-list: [
"A" 11
"B" 22
]
gui-layout: [
box "<-- back to names" [screen1]
text reform ["clicked id " emp-id ", now choose below"]
]
foreach [choice-name choice-id] choice-list [
append gui-layout compose/deep [
box (choice-name) [print [(emp-id) (choice-id)]]
]
]
view layout gui-layout
]
screen1
现在,如果您点击某人然后点击“返回”,菜单就会增长。 (如果你点击其他人,第二个菜单也会增长。)我发现一个解决方法(?)是在clear emp-list
之前放置view layout gui-layout
来修复第一个屏幕。然而,如果我print emp-list
在那里,我可以看到它不是emp-list
正在增长。怎么会这样?
答案 0 :(得分:4)
您正在使用函数的持久性功能。
见
persist: has [ a ] [ a: [] append a random 100 print a ]
no-persist: has [ a ] [ a: copy [] append a random 100 print a ]
要做你想做的事,请在你追加的每个系列之前加上'副本
gui-layout: copy [ text "click your name" ]
和
gui-layout: copy/deep [
box "<-- back to names" [screen1]
text reform ["clicked id " emp-id ", now choose below"]
]