v2_10 Implementing value objects and a typed data model 实现值对象和具备类型的数据
?
ex2_08
这部分解决两个问题
1.Employee如何作为一个值对象传入数据
2.如何将一系列通用的对象转化为定型数据模型
?
值对象一般不包含任何实施细节或商业逻辑,它只是一个简单的数据对象
?
即,从服务器取得的是XML格式的数据,如何转换成自定义的对象
这里就是简单的循环,将从服务端取到XML数据挨个放到Employee对象,由本例的employees取代上例中的employees
// event handlers ------------------------------------------- protected function employeeService_resultHandler(event:ResultEvent):void { var employeeData:ArrayCollection = event.result.employees.employee; var employee:Employee; for each(var emp:Object in employeeData) { employee = new Employee(); employee.firstName = emp.firstName; employee.lastName = emp.lastName; employee.id = emp.id; employee.title = emp.title; employee.email = emp.email; employee.managerID = emp.managerID; employee.department = emp.department; employee.location = emp.location; employee.deskLocation = emp.deskLocation; employee.city = emp.city; employee.state = emp.state; employee.countryCode = emp.countryCode; employee.directDial = emp.directDial; employee.hireDate = emp.hireDate; employee.evaluation = emp.evaluation; employee.postalCode = emp.postalCode; employee.phone = emp.phone; employees.addItem(employee); } }
?
??
使用Flash builder的数据/服务 功能自动生成值对象
?
创建了值对象之后,XML数据转换过程还是一样,使用一个for循环来赋值
?