Angularjs 如何制作ng重复过滤器

Angularjs 如何制作ng重复过滤器,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,努力实现像这里这样的过滤器 我的数据结构是这样的: $scope.books = [ { id: 'id1', contents: { name: '<span>1Alain du sceau france</span><br><span> Canada Madagascar philipi

努力实现像这里这样的过滤器

我的数据结构是这样的:

$scope.books = [
                {
                    id: 'id1',
                    contents: {
                        name: '<span>1Alain du sceau france</span><br><span> Canada Madagascar philipine</span>',
                        price: 'price1',
                        date: '111'
                    }
                },
                {
                    id: 'id2',
                    contents: {
                        name: '<span>2Name zu Long zu Schreiben Bis Here ist Ein Beispiel</span><br><span>Maneschester Canada Madagascar philipine</span>',
                        price: 'price2',
                        date: '2'
                    }
                },
                .........etc

            ];
$scope.books=[
{
id:'id1',
内容:{
名称:“1加拿大马达加斯加菲律宾”,
价格:“价格1”,
日期:111
}
},
{
id:'id2',
内容:{
名称:'2这里的名字是贝斯皮尔岛
Maneschester Canada Magada philipine', 价格:“价格2”, 日期:“2” } }, 等 ];
但在我的用例中,它似乎只适用于book.contents['date']字段,而不适用于book.contents['name']:我的第一个目标是能够按名称进行过滤,如果我能够同时按名称和日期或所有三个字段名称日期价格进行过滤,那就更好了

在下面

 <li class="animate-repeat fc-event" ng-repeat="book in books| orderBy: book.contents['date'] | filter:q as results track by book.contents['name']"  
             id="{{book.id}}">
  • 要成功实施,我面临很多问题:

    N.B: 
       1) class="animate-repeat" not included with fc-event
          means No : .animate-repeat.fc-event 
          included in CSS File.
       2) orderBy book.contents['date'] is not working: 111 
          is the first one it should be the last one.
          book.contents['date'] uses $sce.trustAsHtml 
          see 173,174,175 lines in js file.
          also it uses ng-bind-html="book.contents['name']"
          see line 38 from html file
    
        3) when filtering by input text : 
           1 it works
           1Alain it doesn't work  which results 
           No results found...
           2Name it doesn't work No results found...
    
    
    <!DOCTYPE html>
    <html ng-app="app">
      <head>
        <meta charset="utf-8" />
        <title>AngularJS Plunker</title>
        <script>document.write('<base href="' + document.location + '" />');</script>
        <script data-require="angular.js@1.0.x" src="https://code.angularjs.org/1.3.15/angular.min.js" data-semver="1.0.7"></script>
        <script type="text/javascript" src="https://github.com/kamilkp/angular-vs-repeat/blob/master/dist/angular-vs-repeat.js"></script>
     <script src="https://code.angularjs.org/1.3.15/angular-animate.min.js"></script>
    </head>
    <body ng-controller="MainCtrl">
    <div id='external-events'>
      <h4 >Draggable books</h4>
      <br><br>I have {{books.length}} Books. They are:
           <input type="search" ng-model="q" placeholder="filter books..." aria-label="filter books" />    
    
              <ul data-drag="true"  data-jqyoui-options="{revert: 'invalid'}" jqyoui-draggable="{index {{$index}},placeholder:true,animate:true}">
          <div class="repeater-container" vs-repeat>
            <!-- N.B: 
                 1) class="animate-repeat" not included with fc-event
                    means No : .animate-repeat.fc-event  included 
                    in CSS File.
                 2) orderBy book.contents['date'] is not working: 111 is                 the first one it should be the last one.
                    book.contents['date'] uses $sce.trustAsHtml 
                    see 173,174,175 lines in js file.
                    also it uses ng-bind-html="book.contents['name']"
                    see line 38 from html file
    
                 3) when filtering by input text : 
                    1 it works
                    1Alain it doesn't work No results found...
                    2Name it doesn't work No results found...
            -->
            <li class="animate-repeat fc-event" ng-repeat="book in books| orderBy: book.contents['date'] | filter:q as results track by book.contents['name']"  
                 id="{{book.id}}">
    
            <div class="circle">{{book.contents['date']}}</div>
            <div class="left content" ng-bind-html="book.contents['name']" id="book_{{book.id}}"></div>
                <div class="left rating">2/10</div>
            <div class="clear"></div>
            </li>
            <li class="animate-repeat" ng-if="results.length === 0">
                    <strong>No results found...</strong>
                </li>
            </div>
          </ul>
      </div>
    <div id='calendar-container'>
      <div id='calendar'></div>
    </div>
    </body>
    </html>    
    
    
    ul {
      list-style-type: none;
    }
    
    ul>li {
      display:block;
        padding-right: 0cm;
        margin-left: 0px;
    }
    
    h4 {
      color: gray;
      display: inline; 
      border-bottom: 3px solid darken($fendersblue, 10);
      padding-bottom: 8px;
      font-size:600;
    }
    
    
    #calendar{
     padding: 0 10px;
     width: 650px;
     float: right;
     margin: 0px 0px 10px 55px;
    }
    
    #external-events {
      width: 500px;
      padding: 0 0px;
      border: 0px solid #ccc;/* gray moyen*/
      background: #eee;/* #5D6D7E;(Blue mat) */ /* #eee color gray*/
      text-align: left;
    }
    
    .repeater-container {
        height: 500px;
         width: 460px;
            overflow: auto;
            box-shadow: 0 0 10px;
            border-radius: 5px;
        z-index: 100;
            -webkit-overflow-scrolling: touch;
    
    }
    
    
    #external-events .fc-event {
      cursor: pointer;
      z-index: 100;
      background: #eee;
      border: solid 1px black;
      border-radius: 2px;
      margin-bottom:5px;
    }
    
    .content span
    {
      color: gray;
    }
    .fc-event span:first-child
    {
      font-size: 25px;
      font-weight: bold italic;
    }
    
    
    
    .fc-event div
    {
      padding:3px;
      margin-right:5px;
      height: 100%;
    }
    
    .content
    {
      float:left;
      max-width:75%;
    }
    
    .clear
    {
      clear:both;
    }
    
    .circle {
      float:left;
      width: 10%;
      height: 25%;
      padding: 0 10px;
      border-radius: 360px;
    
    
      /* Just making it pretty */
      @shadow: rgba(0, 0, 0, .1);
      @shadow-length: 4px;
      -webkit-box-shadow: 0 @shadow-length 0 0 @shadow;
              box-shadow: 0 @shadow-length 0 0 @shadow;
      text-shadow: 0 @shadow-length 0 @shadow;
      background: #FFFFFF;/*color white*/
      color: #f05907;/* color red*/
      font-family: Helvetica, Arial Black, sans;
      font-size: 10;
      text-align: center;
    }
    
    .rating
    {
      float:right;
      background: #FFFFFF;/*color white*/
      color: #f05907;/* color red*/
      font-family: Helvetica, Arial Black, sans;
      font-size: 10;
      text-align: center;
      border-radius: 360px;
    }
    
    .animate-repeat {
      line-height:30px;
      list-style:none;
      box-sizing:border-box;
    }
    
    .animate-repeat.ng-move,
    .animate-repeat.ng-enter,
    .animate-repeat.ng-leave {
      transition:all linear 0.5s;
    }
    
    .animate-repeat.ng-leave.ng-leave-active,
    .animate-repeat.ng-move,
    .animate-repeat.ng-enter {
      opacity:0;
      max-height:0;
    }
    
    .animate-repeat.ng-leave,
    .animate-repeat.ng-move.ng-move-active,
    .animate-repeat.ng-enter.ng-enter-active {
      opacity:1;
      max-height:30px;
    }
    (function(angular) {
      'use strict';
    var app = angular.module("app", ['ngAnimate']);
    app.controller("MainCtrl", ['$scope', '$sce', function($scope, $sce){
    
      $scope.books = [
                    {
                        id: 'id1',
                        contents: {
                            name: '<span>1Alain du sceau france</span><br><span> Canada Madagascar philipine</span>',
                            price: 'price1',
                            date: '111'
                        }
                    },
                    {
                        id: 'id2',
                        contents: {
                            name: '<span>2Name zu Long zu Schreiben Bis Here ist Ein Beispiel</span><br><span>Maneschester Canada Madagascar philipine</span>',
                            price: 'price2',
                            date: '2'
                        }
                    },
                    {
                        id: 'id3',
                        contents: {
                            name: '<span>3name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price3',
                            date: '3'
                        }
                    },
                    {
                        id: '4',
                        contents: {
                            name: '<span>4name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price4',
                            date: '4'
                        }
                },
                {
                        id: 'id5',
                        contents: {
                            name: '<span>5name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price5',
                            date: '5'
                        }
                },
                {
                        id: 'id6',
                        contents: {
                            name: '<span>6name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price6',
                            date: '6'
                        }
                },
                {
                        id: 'id7',
                        contents: {
                            name: '<span>7name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price7',
                            date: '7'
                        }
                },
                {
                        id: 'id8',
                        contents: {
                            name: '<span>8name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price8',
                            date: '8'
                        }
                },
                {
                        id: 'id9',
                        contents: {
                            name: '<span>9name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price9',
                            date: '9'
                        }
                },
                   {
                        id: 'id10',
                        contents: {
                            name: '<span>10Alain du sceau france</span><br><span> Canada Madagascar philipine</span>',
                            price: 'price10',
                            date: '10'
                        }
                    },
                    {
                        id: 'id11',
                        contents: {
                            name: '<span>11Name zu Long zu Schreiben Bis Here ist Ein Beispiel</span><br><span>Maneschester Canada Madagascar philipine</span>',
                            price: 'price11',
                            date: '11'
                        }
                    },
                    {
                        id: 'id12',
                        contents: {
                            name: '<span>12name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price12',
                            date: '12'
                        }
                    },
                    {
                        id: 'id13',
                        contents: {
                            name: '<span>13name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price13',
                            date: '13'
                        }
                },
                {
                        id: 'id14',
                        contents: {
                            name: '<span>14name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price14',
                            date: '14'
                        }
                },
                {
                        id: 'id15',
                        contents: {
                            name: '<span>15name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price15',
                            date: '15'
                        }
                },
                {
                        id: 'id16',
                        contents: {
                            name: '<span>16name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price16',
                            date: '16'
                        }
                },
                {
                        id: 'id17',
                        contents: {
                            name: '<span>17name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price17',
                            date: '17'
                        }
                },
                {
                        id: 'id18',
                        contents: {
                            name: '<span>18name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price18',
                            date: '18'
                        }
                },
                {
                        id: 'id19',
                        contents: {
                            name: '<span>19name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price19',
                            date: '19'
                        }
                },
                {
                        id: 'id20',
                        contents: {
                            name: '<span>20name Aleatoire Schwer und zu Leicht Zu Schreiben</span><br><span>Mexico Canada USA France Uk Deutschland Schweiz Madagascar philipine</span>',
                            price: 'price20',
                            date: '20'
                        }
                }
                ];
    
    
    
    
    
      $scope.books.forEach(function(book) {
        book.contents.name =  $sce.trustAsHtml(book.contents.name);
      })
    
      $scope.h = function(html) {
        return $sce.trustAsHtml(html);
      };
    
    
     $(document).ready( function(){     
                        //Initialise external events
                        initialise_external_event('.fc-event');
                        initialise_calendar();
    
        });
    
    
    
    
    
      // initialize the external events
      // -----------------------------------------------------------------
    function initialise_external_event(selector){
    
      $('#external-events .fc-event').each(function() {
    
      var reccupuredIndex=$(this).closest('li.fc-event').attr('id');
      var textContenu=$("#"+ "book_" +reccupuredIndex).html();
      /*
      $("div.left.content").each(function( index, element ) {
              // element == this
              // $( element ).css( "backgroundColor", "yellow" );
             var reccupuredIndexToSee=$(this).closest('li.fc-event').attr('id');
             var textContenuToSee=$("#"+"book_"+reccupuredIndexToSee).text();
    
             var myIndex="book_" +reccupuredIndexToSee;
             if ( $(this).is( "#"+myIndex) )  {
    
               alert($(this).text());
    
              }
      });
      */
    
        var myTitle=$.trim($(this).text());
        //$("span").text( "length:" +$("p.intro").get(0));
    
        // store data so the calendar knows to render an event upon drop
        $(this).data('event', {
          title: $.trim($(this).text()), // use the element's text as the event title
          stick: true // maintain when user navigates (see docs on the renderEvent method)
        });
    
        // make the event draggable using jQuery UI
        $(this).draggable({
          zIndex: 999,
          revert: true,      // will cause the event to go back to its
          revertDuration: 0  //  original position after the drag
        });
    
      });
    
    }
      function initialise_calendar(){
      // initialize the calendar
      // -----------------------------------------------------------------
    
      $('#calendar').fullCalendar({
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar
        drop: function() {
          // is the "remove after drop" checkbox checked?
          if ($('#drop-remove').is(':checked')) {
            // if so, remove the element from the "Draggable Events" list
            $(this).remove();
          }
        },
        eventDragStop: function(event, jsEvent, ui, view ) {
    
                          if(isEventOverDiv(jsEvent.clientX, jsEvent.clientY)) {
    
    
                              //////////
                              $('#calendar').fullCalendar('removeEvents', event._id);
                     var el = $( "<div class='fc-event'>" ).appendTo('#external-        events').text(event.id);
    
        }
                }            
      });
    var isEventOverDiv = function(x, y) {
    
                        var external_events = $( '#external-events' );
                        var offset = external_events.offset();
                        offset.right = external_events.width() + offset.left;
                        offset.bottom = external_events.height() + offset.top;
    
                        // Compare
                        if (x >= offset.left
                            && y >= offset.top
                            && x <= offset.right
                            && y <= offset .bottom) { return true; }
                        return false;
    
                    }
     }
    
    }]);
    })(window.angular);
    
    N.B.:
    1) class=“动画重复”不包括在fc事件中
    表示否:。animate-repeat.fc-event
    包含在CSS文件中。
    2) orderBy book.contents['date']不起作用:111
    是第一个,应该是最后一个。
    book.contents['date']使用$sce.trustAsHtml
    请参阅js文件中的173174175行。
    它还使用ng bind html=“book.contents['name']”
    参见html文件的第38行
    3) 按输入文本过滤时:
    1它起作用了
    1说它不起作用,结果是什么
    没有找到结果。。。
    2名称它不起作用未找到结果。。。
    安古拉斯普朗克
    文件。写(“”);
    可拖动的书
    

    我有几本书。他们是:
    • {{book.contents['date']} 2/10
    • 未找到任何结果…
    保险商实验室{ 列表样式类型:无; } ul>li{ 显示:块; 右侧填充:0厘米; 左边距:0px; } h4{ 颜色:灰色; 显示:内联; 底部边框:3倍纯色深色($fendersblue,10美元); 垫底:8px; 字号:600; } #历法{ 填充:0 10px; 宽度:650px; 浮动:对; 利润率:0px 0px 10px 55px; } #外部事件{ 宽度:500px; 填充:0 0px; 边框:0px实心#ccc;/*灰色moyen*/ 背景:#eee;/*#5D6D7E;(蓝色垫)*/*#eee颜色为灰色*/ 文本对齐:左对齐; } .中继器容器{ 高度:500px; 宽度:460px; 溢出:自动; 盒影:0 10px; 边界半径:5px; z指数:100; -webkit溢出滚动:触摸; } #外部事件.fc事件{ 光标:指针; z指数:100; 背景:#eee; 边框:实心1px黑色; 边界半径:2px; 边缘底部:5px; } .内容跨度 { 颜色:灰色; } .fc事件范围:第一个子级 { 字体大小:25px; 字体大小:粗体斜体; } .fc事件组 { 填充:3倍; 右边距:5px; 身高:100%; } .内容 { 浮动:左; 最大宽度:75%; } 清楚的 { 明确:两者皆有; } .圆圈{ 浮动:左; 宽度:10%; 身高:25%; 填充:0 10px; 边界半径:360px; /*只是让它变得漂亮而已*/ @阴影:rgba(0,0,0,1); @阴影长度:4px; -webkit盒阴影:0@阴影长度0@阴影; 框阴影:0@阴影长度0@阴影; 文本阴影:0@阴影长度0@阴影; 背景:#FFFFFF;/*白色*/ 颜色:#f05907;/*红色*/ 字体系列:Helvetica,Arial黑色,sans; 字号:10 ;; 文本对齐:居中; } 评级 { 浮动:对; 背景:#FFFFFF;/*白色*/ 颜色:#f05907;/*红色*/ 字体系列:Helvetica,Arial黑色,sans; 字号:10 ;; 文本对齐:居中; 边界半径:360px; } .设置重复动画{ 线高:30px; 列表样式:无; 框大小:边框框; } .设置动画-重复.ng-移动, .设置动画-重复.ng-enter, .设置动画-重复.ng-离开{ 过渡:全线性0.5s; } .设置动画-重复.ng-left.ng-left-active, .设置动画-重复.ng-移动, .设置动画-重复.ng-enter{ 不透明度:0; 最大高度:0; } .设置动画-重复.ng-离开, .设置动画-重复.ng-move.ng-move-active, .设置动画-重复.ng-enter.ng-enter-active{ 不透明度:1; 最大高度:30px; } (功能(角度){ "严格使用",; var-app=angular.module(“app”,['ngAnimate']); app.controller(“MainCtrl”[“$scope”,“$sce”,函数($scope,$sce){ $scope.books=[ { id:'id1', 内容:{ 名称:“1加拿大马达加斯加菲律宾”, 价格:“价格1”, 日期:111 } }, { id:'id2', 内容:{ 名称:'2这里的名字是贝斯皮尔岛
    Maneschester Canada Magada philipine', 价格:“价格2”, 日期:“2” } }, { id:'id3', 内容:{ 名称:3墨西哥加拿大美国法国美国
    <!DOCTYPE html>
    <html ng-app="app">
      <head>
        <meta charset="utf-8" />
        <title>AngularJS Plunker</title>
        <script>document.write('<base href="' + document.location + '" />');</script>
        <script data-require="angular.js@1.0.x" src="https://code.angularjs.org/1.3.15/angular.min.js" data-semver="1.0.7"></script>
        <script type="text/javascript" src="https://github.com/kamilkp/angular-vs-repeat/blob/master/dist/angular-vs-repeat.js"></script>
     <script src="https://code.angularjs.org/1.3.15/angular-animate.min.js"></script>
    </head>
    <body ng-controller="MainCtrl">
    <div id='external-events'>
      <h4 >Draggable books</h4>
      <br><br>I have {{books.length}} Books. They are:
           <input type="search" ng-model="searchText" placeholder="filter books..." aria-label="filter books" />    
    
              <ul data-drag="true"  data-jqyoui-options="{revert: 'invalid'}" jqyoui-draggable="{index {{$index}},placeholder:true,animate:true}">
          <div class="repeater-container" vs-repeat>
            <!-- N.B: 
                 1) class="animate-repeat" not included with fc-event
                    means No : .animate-repeat.fc-event  included 
                    in CSS File.
                 2) orderBy book.contents['date'] is not working: 111 is                 the first one it should be the last one.
                    book.contents['date'] uses $sce.trustAsHtml 
                    see 173,174,175 lines in js file.
                    also it uses ng-bind-html="book.contents['name']"
                    see line 38 from html file
    
                 3) when filtering by input text : 
                    1 it works
                    1Alain it doesn't work No results found...
                    2Name it doesn't work No results found...
            -->
            <li class="animate-repeat fc-event" ng-repeat="book in books | orderBy: book.contents.date| filter:searchText as results track by book.contents.name"  
                 id="{{book.id}}">
    
            <div class="circle">{{book.contents['date']}}</div>
            <div class="left content" ng-bind-html="trustAsHtml(book.contents['name'])" id="book_{{book.id}}"></div>
                <div class="left rating">2/10</div>
            <div class="clear"></div>
            </li>
            <li class="animate-repeat" ng-if="results.length === 0">
                    <strong>No results found...</strong>
                </li>
            </div>
          </ul>
      </div>
    <div id='calendar-container'>
      <div id='calendar'></div>
    </div>
    </body>
    </html>