可参考文章:
ng-repeat信息展示的核心:
【1】异步读取数据源 works,见代码一
【2】使用AngularJs控件绑定数据源,见代码三
ng-repeat="work in works "
ng-model="work.company"
ng-model="work.workplace"
【3】保存修改数据,在循环体内,可以将单条记录做形参传递给方法,从而实现保存,见代码二
ng-click="saveWork(work);"
代码一 1 //查看员工背景资料 2 $http({ 3 method : 'POST', 4 url : '/omss/viewEmpBackgroudById?id='+id 5 }).success(function(data, status, headers, config) { 6 $scope.status = status; 7 if (data.length != 0) { 8 $scope.employeeBg = (data[0]); 9 console.log("员工背景data:"+JSON.stringify(data))10 //获取页面中下拉框的数据源11 /*$scope.types =[12 {name:'正式员工',id:'1', xorder:'1'},13 {name:'劳务工', id:'22',xorder:'2'},14 {name:'实习生', id:'23',xorder:'3'} 15 ];*/ 16 //性别17 $scope.genders =[18 {TITLE:'男',ID:'1', xorder:'1'},19 {TITLE:'女', ID:'2',xorder:'2'} 20 ];21 $scope.selectedbggender=(data[0]).bggender; 22 //循环多个工作经历23 $scope.works=(data[0]).workList; //读取数据源24 $scope.edus=(data[0]).eduList; 25 $scope.familys=(data[0]).familyList; 26 }27 }).error(function(data, status, headers, config) {28 $scope.data = data || "Request failed";29 $scope.status = status;30 $scope.tips = '对不起,您的网络情况不太稳定。';31 });
代码二 1 2 3 /* 保存员工工作经历 4 */ 5 $scope.saveWork = function(work) { 6 console.log("进入saveWork........."); 7 var postJson = { 8 'id':work.id,//传递过来的work本来就带有的属性,只是页面未展示 9 'sid':work.sid,//传递过来的work本来就带有,只是页面未展示10 'workbegindate':work.workbegindate,11 'workenddate':work.workenddate,12 'company':work.company,13 'job':work.job,14 'workplace':work.workplace,15 'tel':work.tel,16 'isout':work.isout,17 'remark':work.remark, 18 };19 $http({20 method : 'POST',21 url : '/omss/saveWork',22 data : JSON.stringify(postJson)23 }).success(function(data, status, headers, config) {24 $scope.status = status;25 console.log(data);26 alert("保存成功");27 }).error(function(data, status, headers, config) {28 $scope.data = data || "Request failed";29 $scope.status = status;30 $scope.tips = '对不起,您的网络情况不太稳定。';31 });32 33 };34
代码三 1 2 312 13工作经历
14 15 16 118