AngularJS自定义过滤器基于数据评级(正/负);

时间:2016-08-05 13:04:45

标签: angularjs filter

我正在尝试为我的filter数据创建自定义scope,并且我的JSON文件中包含评级,您可以从下拉列表中选择看到正面或负面评级或所有默认行为。现在我将数据加载到JSON。我不知道如何传递数据和更新视图

js 文件:

var self = this;
self.data = [{"subject":"math","grade":1},
  {"subject":"chemistry","grade":-1},
  {"subject":"gym","grade":0.8},
  {"subject":"music","grade":-0.8}]   

 self.rating = function(){
  } 

HTML

 <select name="grade" id="" ng-model="rating" >
                    <option value="all">all</option>
                    <option value="positive">positive</option>
                    <option value="negative">negative</option>
                </select>
                    <ul>
                <li ng-repeat="opt in self.data  | orderBy:'grade' |     
                 filter:self.rating"">
                    {{opt.subject +" " + opt.grade}}
                </li>
            </ul>

0 个答案:

没有答案