问题描述
好的,我正在尝试在另一个视图中获取列表元素以查看更多详细信息并与之交互。现在,这是代码片段:(注意,这是在导航视图中,语法是正确的)
//below is listed before the body
@Observedobject var jobviewmodel: Jobviewmodel
//The rest is a snippet of the code in question
List{
ForEach(jobviewmodel.jobs){ job in
let jobDate = ParserDate(date: job.date)
if job.completed == false && jobDate == comparisonDate{
let jobTime = ParserTime(time: job.date)
NavigationLink(destination: dummy(job: job))
{
vstack(alignment: .leading){
HStack{
Text("Boat Name")
Spacer()
.frame(width: 50,height: 50)
Text(job.boatName)
}
//Text(job.boatID)
HStack{
Text("Job Time")
Spacer()
.frame(width: 50,height: 50)
Text(jobTime)
}
HStack{
Text("Job Type")
Spacer()
.frame(width: 50,height: 50)
Text(job.job)
}
HStack{
Text("Owner's Name")
Spacer()
.frame(width: 50,height: 50)
Text(job.ownerName)
//Text(job.time)
}
}
}
}
}
}
这是目前的虚拟视图:
import SwiftUI
struct dummy: View {
let job: Job
var body: some View {
Text("Placeholder for job details,will not exists in production,please delete")
vstack(alignment: .leading){
HStack{
Text("Boat Name")
Spacer()
.frame(width: 50,height: 50)
Text(job.boatName)
}
Text(job.boatID)
/*HStack{
Text("Job Time")
Spacer()
.frame(width: 50,height: 50)
Text(jobTime)
}*/
HStack{
Text("Job Type")
Spacer()
.frame(width: 50,height: 50)
Text(job.job)
}
HStack{
Text("Owner's Name")
Spacer()
.frame(width: 50,height: 50)
Text(job.ownerName)
//Text(job.time)
}
}
}
}
struct dummy_Previews: PreviewProvider {
static var previews: some View {
dummy(job: Job[0])
}
}
在“dummy(job: Job[0])”行上,我收到此错误: 类型“作业”没有成员“下标”。我不知道我哪里出错了。任何帮助表示赞赏。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)