2012-10-05 48 views
1

我有這樣的代碼:爲什麼REBOL佈局似乎是持久的?

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 

現在,如果你點擊然後有人點擊「後退」,菜單增長。 (如果你點擊其他人,第二個菜單也會增長。)我發現的一個解決方法(?)是在view layout gui-layout之前將clear emp-list修正爲第一個屏幕。然而,如果我在那裏,我可以看到它不是emp-list,它正在增長。怎麼會這樣?

+0

每個系列我也試過'之前清除gui-layout',並使用'has'(或'screen2'的'function')製作本地和本地佈局,但這些都不能達到只畫一個新的lis每次都是。 – Kev

回答

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"] 
    ] 
+0

太棒了!顯然,我並不知道這個功能。謝謝你的幫助! – Kev

+0

不是一個VID的問題...嗯,我應該更仔細地閱讀它。 :-P – HostileFork