如何在角度ui网格中重复ng-tags-input?

时间:2015-10-11 04:57:35

标签: angularjs angular-ui-grid ng-tags-input

这是我的代码



// Code goes here

var app = angular.module('app', ['ui.grid','ngTagsInput']);

app.controller('TableCrtl', ['$scope', function ($scope) {
        $scope.addData = function () {
            var n = $scope.gridOpts.data.length + 1;
            $scope.gridOpts.data.push({
                "firstName": "New " + n,
                "lastName": "Person " + n,
                "company": "abc",
                "employed": true
            });
        };
        

        var data2 = [
            {
                "firstName": "Waters",
                "lastName": "Shepherd",
                "company": "Kongene",
                "employed": true
            },
            {
                "firstName": "Hopper",
                "lastName": "Zamora",
                "company": "Acium",
                "employed": true
            },
            {
                "firstName": "Marcy",
                "lastName": "Mclean",
                "company": "Zomboid",
                "employed": true
            },
            {
                "firstName": "Tania",
                "lastName": "Cruz",
                "company": "Marqet",
                "employed": true
            },
            {
                "firstName": "Kramer",
                "lastName": "Cline",
                "company": "Parleynet",
                "employed": false
            },
            {
                "firstName": "Bond",
                "lastName": "Pickett",
                "company": "Brainquil",
                "employed": false
            }
        ];

        var origdata2 = angular.copy(data2);

        var myDummyData = [{name: "Moroni", age: 50},
            {name: "Tiancum", age: 43,othernames:[{"id":"101","name":"one"},{"id":"102","name":"two"}]},
            {name: "Jacob", age: 27,othernames:[{"id":"103","name":"three"}]},
            {name: "Nephi", age: 29},
            {name: "Enos", age: 34}];
      

        $scope.filterOptions = {
            filterText: ''
        };
        
        $scope.gridOpts = {
            data: myDummyData,
            enableFiltering: true,
            columnDefs: [
                        {name: 'Name', field: 'name', enableFiltering: true
                            , filter: {
                                term: $scope.filterOptions.filterText //DOES NOT WORK... BUT WHY
                            }
                        },
                        {name: 'Price', field: 'age'},
                        {name:'others',field:'othernames',cellTemplate:'<tags-input display-property="name replace-spaces-with-dashes="false" template="tag-template">'}
                    ]
        };
        
        
      
     
    }]);
&#13;
/* Styles go here */

.cart-item.ng-enter {
  -webkit-transition:0.5s linear all;
  transition:0.5s linear all;
  background-color: yellow;
}
.cart-item.ng-enter-active {
  background-color: white;
}

.myGrid {
    width: 1200px;
    height: 800px;
}
&#13;
<!doctype html>
<html ng-app="app">
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-touch.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-animate.js"></script>
        
        <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
        <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
        <script src="http://ui-grid.info/release/ui-grid-unstable.js"></script>
        
       
        
        <link data-require="bootstrap-css" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
        <link data-require="bootstrap@*" data-semver="3.2.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
    
        <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.css" type="text/css">
        <link rel="stylesheet" href="style.css" type="text/css">
        <link rel="stylesheet" href="http://mbenford.github.io/ngTagsInput/css/ng-tags-input.min.css" />
        <link href="https://github.com/danielcrisp/angular-rangeslider/blob/master/angular.rangeSlider.css" rel="stylesheet" type="text/css"/>
        <script src="https://github.com/danielcrisp/angular-rangeslider/blob/master/angular.rangeSlider.js" type="text/javascript"></script>
       <script src="http://mbenford.github.io/ngTagsInput/js/ng-tags-input.min.js"></script>
    </head>
    <body ng-controller="TableCrtl">

        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">-------========TEST========-------</a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#/">Home</a></li>
                        <li><a href="#/about">Impressum</a></li>
                   </ul>
                    <form class="navbar-form navbar-left" role="search">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Produkt Name" ng-model="filterOptions.filterText">
                        </div>
                        <button type="submit" class="btn btn-default" ng-click="activateFilter()">Suchen</button>
                    </form>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
        
        
        <div>
            
           
            <input type="text" class="form-control" placeholder="Produkt Name" ng-model="filterOptions.filterText">
            <br>
            <div range-slider min="0" max="100" model-min="15" model-max="35"></div>
            <br>
            <div id="grid1" ui-grid="gridOpts" class="grid"></div>
        </div>

        <script src="script.js"></script>
        
        
        
    </body>
</html>
&#13;
&#13;
&#13;

在上面的代码中我有3列,第三列包含其他名称,如数组,我想只以标签格式打印这些名称。如何使用角度ui-grid在列中以标签格式重复其他名称。 这是我的傻瓜:http://plnkr.co/edit/hNKDh1zWWSNJzmqDMbdW?p=preview

1 个答案:

答案 0 :(得分:2)

首先,升级角度版本(应大于1.3。*)以使ng-tags-input工作 其次,您尚未定义“标签模板”。

第三栏的CellTemplate:

<tags-input ng-model="row.entity.othernames" display-property="name" replace-spaces-with-dashes="false">

这里是没有tag-template的工作代码。 http://plnkr.co/edit/ZrVN988WXn2au7xN1reV?p=preview