2011-06-19 35 views
2

我試過,但顏色是未知的(我找遍了互聯網驚人的沒有一個人記錄了它!):如何獲得Rebol中的單選按鈕值?

V: view layout [ 
    across 
    label "Colours:" 
    r: radio of 'colours l: label "Red" 
    radio of 'colours label "Green" 
    radio of 'colours label "Blue" 
    return 
    label "Fruits:" 
    radio of 'fruits label "Apples" 
    radio of 'fruits label "Oranges" 
    button "close" [unview] 
] 

probe colors 

回答

2

我相信單選按鈕設計,你命名,並檢查每個按鈕:

mycolours: view layout [ 
    red: radio of 'colours label "Red" 
    green: radio of 'colours label "Green" 
    blue: radio of 'colours label "Blue" 
] 

probe red/data 
probe green/data 
probe blue/data 

要從單詞「顏色」中獲得答案,您將不得不通過面遍歷來找到具有該關係的面。這裏有一個快速和骯髒的迭代器(walk-vid):

walk-vid: use [level][ 
    level: 0 

    func [[catch] face [object!] callback [function!] /deep][ 
     unless in face 'pane [throw make error! "Not a face"] 
     either deep [level: level + 1][level: 0 bind second :callback 'level] 

     do [callback face] 
     case [ 
      block? face/pane [ 
       foreach pane face/pane [walk-vid/deep pane :callback] 
      ] 
      object? face/pane [ 
       walk-vid/deep face/pane :callback 
      ] 
     ] 
     either deep [level: level - 1][level: 0] 
     face 
    ] 
] 

所以,遍歷面孔,找到關係,找到選定的面。讓我們爲一個函數:

which-radio: func [face [object!] group [word!] /local selected][ 
    walk-vid face func [face][all [face/related = group face/data selected: face]] 
    selected 
] 

因此包裹起來:

probe which-radio mycolours 'colours 

爲了使生活更輕鬆,你可以添加一張臉/文本值的單選按鈕(標籤不綁定按鈕):

radio of 'colours "Red" label "Red" 
+0

哦,我真不敢相信它有那麼複雜:爲什麼地球上無法識別顏色只返回[假真假]例如:) –

+0

最後它的確定它甚至可以方便的http:/ /askcodegeneration.com/jquery/ :) –

+0

我不知道爲什麼會這麼痛苦,或者一個類似的解決方案沒有烘焙到VID中。我不知道是否不願意將這個值賦予全球性詞語「colours」而沒有特定的詞彙表示法。 – rgchris

0

VID方言不提供此類功能,但它很容易添加。

REBOL [] 

stylize/master [ 
    radio: radio with [ 
     get-all: has [list][ 
      if related [ 
       list: make block! 3 
       foreach item parent-face/pane [ 
        all [ 
         item/related 
         item/related = related 
         append list to-logic item/data 
        ] 
       ] 
       list 
      ] 
     ] 
    ] 
] 

view layout [ 
    across 
    label "Colours:" 
    r: radio of 'colours l: label "Red" 
    radio of 'colours label "Green" 
    radio of 'colours label "Blue" 
    return 
    label "Fruits:" 
    f: radio of 'fruits label "Apples" 
    radio of 'fruits label "Oranges" 
    button "close" [unview] 
] 

print ["colours:" mold r/get-all] 
print ["fruits:" mold f/get-all] 

假如你想改變所有無線電按鈕樣式,否則你將需要刪除/主細化。

0

在R3GUI單選按鈕按近點分組,您可以通過命名每個按鈕來獲取它們的值。

view [ 
    r1: radio "one" 
    r2: radio "two" 
    r3: radio "three" 
    button "show" on-action [ print get-face reduce [ r1 r2 r3 ]] 
]