如何根据先前列表的变量创建列表

How do you create a list based on a previous list's variable

我有一个选择列表。无论您在列表中做出什么选择,都应该决定下一个列表中可用的选择。我目前收到

错误 "Can’t get item 1 of \"\"."项目 1 中的编号 -1728 ""

第一个列表中的 set 变量似乎没有输入到 If Else If 语句中。

    set currentSupport to "" -- initialize the variable
    set supportList to choose from list {"A", "B"} with prompt "Source:" default items {"A"}
    set currentSupport to result

    set currentPR to "" -- initialize the variable
    if currentSupport is "A" then
        set misrouteList to choose from list {"1", "2", "3", "4"} with title "Prepared Responses" with prompt "Reason:"
        set currentPR to result
    else if currentSupport is "B" then
        set misrouteList to choose from list {"5", "6", "7", "8", "9", "10"} with title "Prepared Responses" with prompt "Reason:"
        set currentPR to result
    end if


    set supportChoice to item 1 of currentSupport
    set prChoice to item 1 of currentPR

choose from list returns false 如果用户按下 Cancellist 甚至 with multiple selections未启用。

您必须在 if - else 表达式

之前展开列表
set currentSupport to "" -- initialize the variable
set supportList to choose from list {"A", "B"} with prompt "Source:" default items {"A"}
if supportList is false then return
set currentSupport to item 1 of supportList

set currentPR to "" -- initialize the variable
if currentSupport is "A" then
    set misrouteList to choose from list {"1", "2", "3", "4"} with title "Prepared Responses" with prompt "Reason:"
    if misrouteList is false then return
    set currentPR to item 1 of misrouteList
else if currentSupport is "B" then
    set misrouteList to choose from list {"5", "6", "7", "8", "9", "10"} with title "Prepared Responses" with prompt "Reason:"
    if misrouteList is false then return
    set currentPR to item 1 of misrouteList
end if


set supportChoice to currentSupport
set prChoice to currentPR

或无冗余代码

set supportList to choose from list {"A", "B"} with prompt "Source:" default items {"A"}
if supportList is false then return
set currentSupport to item 1 of supportList

if currentSupport is "A" then
    set responseList to {"1", "2", "3", "4"}
else -- there is only A or B
    set responseList to {"5", "6", "7", "8", "9", "10"}
end if
set misrouteList to choose from list responseList with title "Prepared Responses" with prompt "Reason:"
if misrouteList is false then return
set currentPR to item 1 of misrouteList

set supportChoice to currentSupport
set prChoice to currentPR

或将选择保留为列表并检查 {"A"}

set supportList to choose from list {"A", "B"} with prompt "Source:" default items {"A"}
if supportList is false then return
if supportList is {"A"} then
    set responseList to {"1", "2", "3", "4"}
else
    set responseList to {"5", "6", "7", "8", "9", "10"}
end if
set misrouteList to choose from list responseList with title "Prepared Responses" with prompt "Reason:"
if misrouteList is false then return

set supportChoice to item 1 of supportList
set prChoice to item 1 of misrouteList