我正在使用一些数据来获取图书列表,如下所示:-
1 1001 - 500 - Lords of the Ring 引用(InputBox) 备注(InputBox) SubmitBox
2 1002 - 570 - 哈利波特引用(InputBox) 备注(InputBox) SubmitBox
3 1003 - 720 - 达芬奇代码引用(InputBox) 备注(InputBox) SubmitBox
我可以使用下面的代码到达上面。但是,我不知道如何将数据保存到另一个数据库,如果有人可以指导我,我将不胜感激。
这是我的 html 代码:-
<form name="Bookentry" ng-submit="save()">
<div ng-repeat="lists in list.Books | orderBy: ['numB','numB1' ]">
<ng-form name="item">
{{$index+1}}
<input type="checkbox" ng-click="delete(lists._id)">{{lists.numB}} - {{lists.numB1}} - {{lists.bookname}}
<input type="text" name="Reference" ng-model="lists.Reference" ng-maxlength="8" ng-minlength="1"></input>
<input type="text" name="Remarks" ng-model="lists.Remarks" ng-maxlength="8" ng-minlength="1"></input>
<button type="submit">Save</button>
</ng-form>
</div>
</form>
我的 core.js 代码是:-
$scope.save = function(){
$http.post('/api/save',$scope.Bookentry)
.success(function(data){
$scope.list = {};
$scope.list.Books = data;
})
.error(function(data){
console.log('Error: ' + data);
});
};
我的 app.js 是:
app.post('/api/save', function(req,res){
dbBooks.create({
numB: req.body.numB,
numB1: req.body.numB1,
name: req.body.bookname,
Reference: req.body.Reference,
remarks: req.body.remarks,
done: false
}, function(err,result){
if (err)
res.send(err);
dbBooks.find(function(err,result){
if (err)
res.send(err)
res.json(result)
});
});
});
最佳答案
您可以将列表模型作为参数传递给保存函数。 html代码:
<form name="Bookentry" ng-submit="save(lists)">
核心js:
$scope.save = function(bookEntry){
$http.post('/api/save',bookEntry)
.success(function(data){
$scope.list = {};
$scope.list.Books = data;
})
.error(function(data){
console.log('Error: ' + data);
});
};
关于javascript - 使用ng-repeat、ng-form、ng-submit后如何提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30730970/