Как создать список на основе переменной предыдущего списка - PullRequest
0 голосов
/ 11 мая 2019

У меня есть список вариантов. Какой бы выбор вы ни делали в списке, он должен определять варианты, доступные в следующем списке. Я сейчас получаю

ошибка"Не удается получить элемент 1 из \" \ "." номер -1728 от 1 из""

Кажется, что переменная 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

1 Ответ

0 голосов
/ 11 мая 2019

choose from list возвращает false, если пользователь нажимает Cancel или список элементов, даже если 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...