我有以下集合:
private Map <String, Staff> staff;
Run Code Online (Sandbox Code Playgroud)
实现为TreeMap:
staff = new TreeMap <String, Staff> ();
Run Code Online (Sandbox Code Playgroud)
我需要迭代这个映射中的值,但是当我尝试下面的代码时,我得到了一个不兼容的类型编译错误.我不明白为什么会这样; 我的地图中的值是Staff对象和
it.HasNext()
Run Code Online (Sandbox Code Playgroud)
应该将它们返回存储在staffMember变量中,这应该对我的知识很好?非常感谢.
Collection <Staff> staffList = staff.values();
Iterator it = staffList.iterator ();
while ((isJobAssigned = false) ||it.hasNext())
{
Staff staffMember = it.next();
if ((staffMember instanceof Typist) && (jobType.equalsIgnoreCase("Typist")))
{
newJob.setJobState ("Assigned");
staffMember.setState("Working");
return newJon.getJobNo() + " Staff allocated: " + staffMember.getName () + ", ID: " + staffMember.getId();
}
Run Code Online (Sandbox Code Playgroud) 我有一个ViewModel,我试图回发以保存在数据库中.虽然ViewModel正在获取//GET Create(int id)它所设置的值,但是当它到达时它会丢失一些//POST Create ().将GoalLevel与GoalTitle正在通过确定已过,但ActorId并ProjectId正在丧失,甚至虽然调试器是通过去if (Model.State.IsValid)块,即正在经历的值没有被保存到数据库中.然后重定向会失败,因为我不再有效ProjectId传递给URL.
如果你知道你在做什么,我相信这是显而易见的!
CONTROLLER
// GET: UseCases/Create
public ActionResult Create(int id)
{
ViewBag.projectId = id;
//Populate the ViewModel
UserGoalsStepViewModel model = new UserGoalsStepViewModel()
{
ProjectId = id,
ActorList = new SelectList(db.Actors.Where(a => a.projectID == id), "id", "Title"),
};
return View(model);
}
// POST: UseCases/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, …Run Code Online (Sandbox Code Playgroud)