我是AngularJs的新手。我在完成这项任务时遇到了一些麻烦。
我有json文件:
[{
"day": {"date": "12.01.2015", "dow": "monday", "in":"1"},
"lessons": [
{"time": "9.45 – 12.35", "title": "title", "teacher": "tname", "room": "3"},
... more lessons ...
]
},
... more days ...
]
我的html文件:
<table style="width: 100%;" class="table table-bordered">
<tbody ng-repeat="timetable in timetables" ng-if="ind==-1||ind==$index">
<tr ng-repeat="lesson in timetable.lessons">
<td rowspan="{{timetable.lessons.length}}" ng-if="!$index" style="vertical-align: top; text-align: left;">
{{timetable.day.date}}<br />
<div style="width: 100%; height: 100%; min-height: 100%; ">
<a href="#/list/{{timetable.day.in - 1}}" > {{timetable.day.dow}}</a></div>
</td>
<td>{{lesson.time}}</td>
<td>{{lesson.title}}</td>
<td>{{lesson.teacher}} <input type="textbox" ng-model="lesson.teacher"/></td>
<td>{{lesson.room}}</td>
</tr>
</tbody>
</table>
controllers.js:
angular.module('schedule.controllers', [])
.controller('ListLessonsCtrl', ['$scope', 'Schedule' , "$routeParams",
function ($scope, Schedule, $routeParams) {
if ($routeParams.ind === undefined) {
$scope.ind = -1;
} else {
$scope.ind = $routeParams.ind;
}
$scope.timetables = Schedule.query(); // get data form json file
$scope.save = function() {
Schedule.save($scope.timetables); // not works properly
};
}
])
... more code ...
最后,我的services.js文件:
angular.module('schedule.services', ['ngResource'])
.factory('Schedule', ['$resource', function($resource) {
return $resource('schedule/schedule.json', {}, {
query: {method: 'GET', isArray: true},
save: {method: 'POST'}
});
}]);
我需要从json文件中获取数据(完成),在页面上更新它(知道如何操作),并将更新的数据保存回json文件。
我尝试将功能“保存”添加到现有工厂,但我不确切知道如何向其发送数据。
有人可以帮我吗?
提前致谢!