2015-06-09 111 views
0

我使用的一些数据如下获取书籍的列表: -如何使用NG重复,NG-形式提交后NG-提交

1 1001 - 500 - 领主戒指参考的(的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) 
    }); 
    }); 
}); 
+0

发送JSON阵列到服务器,然后遍历数组了吗? – com2ghz

+0

我是初学者,需要更多解释。谢谢 –

+0

你使用什么样的REST api? – com2ghz

回答

0

您可以通过列出模型作为保存功能的参数。 的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); 
     }); 
}; 
+0

我试过了但我如何获取我的app.js中的数据? THKS –