首页 > 解决方案 > 如何在茄子的属性列表中动态插入键和值

问题描述

我已获取数据作为列表列表(内部列表由 2 个值组成,例如 (name,sam)),现在我想读取每个内部列表的数据并将第一个数据添加为键并将第二个数据添加为值财产清单。例如,((name,sam),(date,fourth),(age,twenty)) = 列表列表

转换为 = (name:"sam",date:"fourth",age:"twenty") = 属性列表

我怎样才能做到这一点?

set excelRead to WorkBook(ResourcePath(fileName))
set readColumns to excelRead.Worksheet(sheetName)
set listOfData to cellRange("A:B") of readColumns
put (:) into newPlist
repeat with each item of listOfData
    put item 1 of it into key
    put item 2 of it into Value

end repeat

标签: property-listeggplant

解决方案


您只需在变量名周围加上方括号,即可将其用作属性列表中的键:

put Value into newPlist.(key)
put Value into (key) of newPlist
put Value into newPlist's (key)

它在此处的 SenseTalk 参考中:使用变量引用属性列表键


推荐阅读