ng-repeat使用ng-rateit的值

时间:2018-01-17 20:10:00

标签: javascript angularjs

我需要从对象重复键名和来自另一个json对象的值。

avis.name有效,但得分(model.score)并不想显示。救命 对于信息,我使用 angular-rateit 指令

代码看起来像:



            $scope.model = [
                {
                    "score": 5
                },
                {
                    "score": 3
                },
                {
                    "score": 2
                }
            ]
            
            $scope.allavispossible = [
            {
            "name": "presentation"
            },
            {
            "name": "efficacite"
            },
            "name": "puissance"
            ]

<div ng-repeat="avis in allavispossible">
<span class="namecaracforvoteaddproduct">{{avis.name}}</span><ng-rate-it ng-model="model.score" max="5" step="1" star-width="25" star-height="25" class="bigstar" read-only="false" resetable="false"></ng-rate-it>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您尝试将Array用作对象:ng-model =&#34; model.score&#34;。但是model - 是Array,你需要将它用作Array,f.e。 NG-模型=&#34;模型[0] .score&#34;

答案 1 :(得分:0)

您需要更改每个具有名称和分数的对象的数组,并将ng-model更改为 ng-model="avis.score"

<强>样本

&#13;
&#13;
var app = angular.module('testApp',['ngRateIt']);

app.controller('testCtrl',function($scope){
 
  $scope.allavispossible =[
  {
    "name": "presentation",
    "score": 5
  },
  {
    "name": "efficacite",
    "score": 3
  },
  {
    "name": "puissance",
    "score": 2
  }
];
});
&#13;
<link href="https://github.com/akempes/angular-rateit/blob/master/dist/ng-rateit.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
 <script src="https://raw.githubusercontent.com/jannunzi/educationPortal/master/public/js/ng-rateit.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<div ng-repeat="avis in allavispossible">
<span class="namecaracforvoteaddproduct">{{avis.name}}</span><ng-rate-it ng-model="avis.score" max="5" step="1" star-width="25" star-height="25" class="bigstar" read-only="false" resetable="false"></ng-rate-it>
</div>
&#13;
&#13;
&#13;