【问题标题】:LiveCode find list items within a table fieldLiveCode 在表格字段中查找列表项
【发布时间】:2013-07-12 11:24:05
【问题描述】:

我正在尝试使用 LiveCode 清理一些联系人数据。我有两个列表:

  • SourceList:LiveCode 表字段中以制表符分隔的联系人记录列表;
  • FlagList:我想在 SourceList 中检查的字符串列表,例如“test”。

理想情况下,我想在 FlagList 行和 SourceList 行中的项目中突出显示“命中”,但我在第一次通过时遇到了错误。在从文件加载 SourceList 时,我正在尝试设置 SourceList 中找到的任何 FlagList 字段行的颜色。

这是“加载源列表”按钮上的脚本...

on mouseUp
  answer file "Select text file to Clean" with type "txt"
  if it <> "" then
    put empty into field "Source"
    put it into field "SourceFile"
    put it into theFilePath
    put URL ("file:" & theFilePath) into field "SourceList"
    repeat for each line f in field "FlagList"
      repeat for each line l in field "SourceList"
        repeat for each item i in l
            if i contains f then set the foregroundColor of f to "red"
        end repeat
      end repeat
    end repeat
  else     
    --no file was selected, or cancel was pressed
    beep
  end if
end mouseUp

我认为我犯了一个基本错误,非常感谢任何指导。

【问题讨论】:

    标签: string text contains livecode


    【解决方案1】:

    问题在于 f 是一个字符串,而不是块引用或控件引用。您需要在重复循环中添加一个计数器并编写正确的引用,如下所示:

       put 0 into myCounter
       repeat for each line f in field "FlagList"
          add 1 to myCounter
          repeat for each line l in field "SourceList"
             repeat for each item i in l
                if i contains f then
                   set the foregroundColor of line myCounter of field "FlagList" to "red"
                   exit repeat
                end if
             end repeat
          end repeat
       end repeat
    

    这将从脚本中删除错误。我没有检查它现在是否真的有效(例如,我看不到所有控件引用是否正确)。

    【讨论】:

    • 太棒了!谢谢马克 - 这是一种享受。感谢您澄清“f”在这种情况下只是一个变量。我认为现在可以看到如何从这里构建。
    • 如果你喜欢这个答案,你也可以按向上的三角形;-)
    • 哦,要有足够高的声誉来推广有用的答案! ;-)
    • 或者重新打开无法理解并因此被 Stackoverflow 上必须了解 LiveCode 线索的人关闭的 LiveCode 问题。
    猜你喜欢
    • 2018-12-29
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2018-09-23
    相关资源
    最近更新 更多