当我选择特定部门(名称)并使用该部门名称(获取其部门 ID)并使用该 ID 搜索所有员工数据或所有员工数据时,我使用此代码保存所有员工数据这类似于将部门 ID 保存到数组中并打印它。但是当我使用该代码时,它打印员工 ID nil 并打印所有员工姓名(对于所有部门 ID)
if let deptt = dictData["departments"] as? [Any] {
print(deptt)
for i in deptt as! [[String : Any]]
{
let depttName = i["name"] as? String
let depttID = i["id"] as? String
//print(i["name"]!)
if depttName == selectedDeptt
{
let dd = depttID
print("dddd : \(dd)")
let emp = dictData["employees"] as? [Any]
for j in emp as! [[String : Any]]
{
let empID = j["department_id"] as? String
let empName = j["name"] as? String
print("Employee ID is : \(String(describing: empID))")
if depttID == empID
{
print("Employee ID is : \(String(describing: empID))")
print("Employee Names : \(String(describing: empName))")
arrEmp.append(empName!)
}
}
}
}
}
print(arrEmp)
最佳答案
我认为,您正在将部门 ID 与员工 ID 进行比较,这将不匹配。您应该获取员工的部门 ID,然后将该 ID 与选定的部门 ID 进行比较。
关于ios - 打印所选部门 ID 的所有员工姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49271510/