1

我有这个代码:

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在增长。怎么会这样?

4

1 回答 1

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"]
    ]
于 2012-10-05T19:03:47.107 回答