1

我爲我的公司會計生成一個應用程序。 我列出了一個帳戶的所有操作,從一個ng-repeat的json。 吳重複工作偉大的,但問題是:角度ng-repeat:過濾器在symfony樹枝視圖中不起作用

我想爲操作的名稱添加過濾器的輸入。 該過濾器不起作用,並經過大量的搜索,我不明白爲什麼。

我app.js的代碼(角):

//app.js 

var app = angular.module('app', [], function($interpolateProvider){ 
    $interpolateProvider.startSymbol('<%'); 
    $interpolateProvider.endSymbol('%>'); 
}); 

app.controller('MainController', function ($scope, Account) { 
    $scope.ops = {}; 

    $scope.showOps = function(account_id) { 
    Account.get(account_id) 
     .success(function(data){ 
     $scope.ops = data; 
     }) 
     .error(function(data){ 
     console.log(data); 
     }); 
    } 
}) 

app.factory('Account', function($http){ 
    return { 
    get : function(account_id) { 
     return $http.get('/api/operations/' + account_id); 
    } 
} 
}); 

和代碼我的樹枝模板:

{% block body -%} 
    <div data-ng-init="showOps({{ entity.id }});"> 
    <div class="account-head"> 
     <h1>Compte</h1> 
     {{ form(delete_form) }} 
    </div> 
    <div class="panel-body"> 
     <ul class="list-group"> 
     <li class="list-group-item"> 
      <span class="account-name">{{ entity.name }}</span> 
      <span class="account-actions"> 
      <a class="btn btn-default btn-sm" href="{{ path('account_edit', { 'id': entity.id }) }}">Editer</a> 
      </span> 
     </li> 
     </ul> 
    </div> 
    <input placeholder="Search" data-ng-model="query.name" ng-disabled="isDisabled" type="text"> 
<div data-ng-repeat="op in ops | filter: query"> 
    <p><% op.type %></p> 
    <p><% op.name %></p> 
    <p><% op.montant %></p> 
    <hr> 
    </div> 
</div> 
{% endblock %} 

這應該過濾結果當輸入變化 的值(例如由我:http://chalasr.github.io/#/works) 但我沒有任何反應,當我寫入輸入。 我已經tryed一些型動物過濾器,如:

<div data-ng-repeat="op in ops | filter: {name: someNameInResult}"> 
<div data-ng-repeat="op in ops | filter: {query: query}"> 

但它一點兒也不作品! 如果你能幫助我,請提前致謝!

回答

0

我已經解決我的問題。

解決方案過濾數據對象是這樣的:

$scope.items = { 
    0: {date: new Date('12/23/2013')}, 
    1: {date: new Date('12/23/2011')}, 
    2: {date: new Date('12/23/2010')}, 
    3: {date: new Date('12/23/2015')} 
    }; 

只需添加angular-toArrayFilter作爲依賴於你的應用程序,並使用它:

//Markup: 
<div data-ng-init="showOps({{ entity.id }});"> 
    <div class="account-head"> 
    <h2>Compte: {{ entity.name }}</h2> 
    {{ form(delete_form) }} 
    <a class="btn btn-default btn-sm" href="{{ path('account_edit', { 'id': entity.id }) }}">Editer</a> 
    </div> 
    <input type="text" ng-model="query.name"> 
    <div ng-repeat="ops in ops | toArray | filter: query"> 
    <p><% ops.type %></p> 
    <p><% ops.name %></p> 
    <p><% ops.montant %></p> 
    <hr> 
    </div> 
</div> 

感謝的所有您的幫助,我想其他人可以有這個問題,他們可以在這裏找到解決方案。

0

您的過濾名爲query.name模型,所以改變你的NG-重複過:

data-ng-repeat="op in ops | filter: query.name" 
+0

Thans爲您的答案,但它是行不通的,沒有反應。 我不明白這個問題:'( – chalasr 2015-04-04 20:46:08

+0

你能發表一個ng-repeat迭代的數據的例子嗎?那個ng-repeat是否在沒有任何過濾器的情況下工作? – cheekybastard 2015-04-04 23:48:49