2013-08-27 48 views
0

我對使用ngrepeat填充的每篇文章都有評論功能。 添加的新評論應更新爲評論。ngrepeat中的動態ngmodel值並對其進行處理

<div ng-repeat="Article in Articles"> 
    <div class="Description"> 
     {{Article.Description}} 
    </div> 

    <div class="commentbox"> 
     <textarea placeholder="Share your View" ng-model="Article{{Article.Articleid}}" ></textarea> 

      <div class="post"> 
       <a href="javascript: void(0)" ng-Click="AddComment({{Article.Articleid}});" > Article </a> 
      </div> 
    </div> 
</div> 

和js函數添加的評論是

$scope.AddComment = function(ArticleID){ 
    $scope.Comments.push({ 
     ArticleID: ArticleID, 
     **ReviewText: $scope.Comment130, //how to acess the model of received ArticleID** 
    DateAdded:new Date() 
    }); 

我的問題是如何設置的動態值NG-模型和訪問它在jsfunction。

謝謝

+0

什麼是'NG-模型= 「第{{Article.Articleid}}」'? – Cherniv

回答

1

我認爲你的綁定有點搞砸了。像這樣的東西應該這樣做。觀察收到的對象的控制檯,你可以開始做他們的東西。

http://plnkr.co/edit/ugtbO2

HTML

<div ng-repeat="a in articles" ng-model="article"> 
    <div class="description">{{a.description}} (id: {{a.id}})</div> 
    <div class="commentbox"> 
     <textarea placeholder="Share your View" ng-model="a.review"></textarea> 
     <div class="post"> 
      <button ng-click="addComment(a)" > Submit </button> 
     </div> 
    </div> 
</div> 

JS

$scope.articles = [ 
     {id: '1',description: 'sdfsdf', review:''}, 
     {id: '2',description: 'asa334', review:''}, 
     {id: '3',description: 'dfsdfw3r', review: ''}, 
     {id: '4',description: 'sdfsdf', review: ''} 
    ]; 


$scope.addComment = function (article) { 
    $scope.comments.push({ 
    ArticleID: article.id, 
    ReviewText: article.review, 
    DateAdded : new Date() 
    }); 

    console.log($scope.comments); 
}; 
相關問題