Ng-repeat中的多个表格

时间:2015-01-22 09:05:02

标签: angularjs

ng-repeat中有表格。当我提交任何表格时,每次错误时都会提交最后一份表格。 只有选中的表格需要提交。 我的代码是

<ul rn-carousel rn-carousel-indicator style="list-style: none">
   <li ng-repeat="story in stories">
    <form ng-submit="commentsSubmit($index)" method="post">
       <input type="hidden" ng-init="comment.itemID = story.news_id" ng-model="comment.itemID">
       <input type="hidden" ng-init="comment.owner_id = 1" ng-model="comment.owner_id">
       <input type="hidden" ng-init="comment.type = 'L'" ng-model="comment.type">
       <input type="hidden" ng-init="comment.from = 'app'" ng-model="comment.from">
       <input type="hidden" ng-init="comment.user_id = user_id" ng-model="comment.user_id">
      <input type="hidden" ng-init="comment.redirect = 'story'" ng-model="comment.redirect">
     <textarea ng-model="comment.content" class="textarea" rows="3" placeholder="Your Comment">{{ content }}</textarea>
     <button class="button--cta">Submit</button>
     </form>
   <li>
 </ul>

我是如何实现这一目标的?

1 个答案:

答案 0 :(得分:1)

已经讨论过类似的问题, 仅供参考form submission on ng-repeat

在控制器中传递对象而不是id

$ scope.commentsSubmit = function( story

请按照这样提交<form ng-submit="submit(story)">

$scope.commentsSubmit = function(story){ 
var comments = story;
    $http({ data: $.param($scope.comment) 
    }).success(function(data) { 
        MyCache.put('comments-'+$scope.comment.itemID, data.reviews); 
    }) 
};