2015-06-09 65 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 –