如何使用 swiftui 中的搜索栏过滤列表

How do I filter a list using the search bar in swiftui

如何在 SwiftUI 中使用搜索栏过滤列表。

这是我目前所做的,它显示了列表中的所有信息,但列表没有过滤信息。

ForEach(
  (0..<self.appData.myJobs.count).filter(
    { "\([=10=])".contains(searchBar.text) || searchBar.text.isEmpty  }), 
  id: \.self) { index in

谢谢。

现在您尝试过滤索引(如 1、2、3...),但我假设您尝试按某些文本进行过滤,所以它应该类似于(我现在不知道您的工作属性,所以这只是假设,但思路应该很清楚)

ForEach(
  (0..<self.appData.myJobs.count).filter({ i in // << here you get index 
      // assuming you have .jobTitle property in Job and want to filter by it
      // so just substitute your property
      self.appData.myJobs[i].jobTitle.contains(searchBar.text) || 
      searchBar.text.isEmpty }), 
  id: \.self) { index in