从数组中选择多个,显示结果(Angularjs)

时间:2015-03-22 23:04:45

标签: javascript arrays angularjs ionic

我正在研究Ionic。 我想从侧边菜单中选择(toogle)一些标准。这是html:

 <div ng-app="app">
 <div data-ng-controller="dishTypeListController">
<h1 class="featured_in_mag_name">Available filters criteria</h1>
    <div class="listing_venue_types_filter_page">
    <div class="input_dishtype_selection " 
            data-ng-repeat="dishType in dishTypeList"
            ng-class="{'filter_selected':selection.indexOf($index) != -1}"
                ng-click="toggle($index)">
                {{dishType.name}}</div>                 
    </div> <!-- listing_venue_types_filter_page-->
</div>  

数据来自数组:

var wmapp = angular.module('app',[]);

 wmapp.controller('dishTypeListController', function($scope) {
$scope.dishTypeList = [
    {'name': 'Meat '},
    {'name': 'Soup'},
    {'name': 'Fish'},
    {'name': 'Fruits'},
    {'name': 'entree'},
    {'name': 'snack'}
];
$scope.selection = [];

$scope.toggle = function (idx) {
    var pos = $scope.selection.indexOf(idx);
    if (pos == -1) {
        $scope.selection.push(idx);
    } else {
        $scope.selection.splice(pos, 1);
    }
};

})

如何指出上面对象上的toogling将被用作打印ng-repeat的选择标准?

我曾尝试将一个jsfiddle放在一起说明而不能完成它,https://jsfiddle.net/bmun0mkx/ 希望这很清楚 非常感谢你的帮助。

0 个答案:

没有答案