带过滤器的ng-filter未过滤

时间:2016-09-13 06:24:30

标签: angularjs angularjs-ng-repeat

您好我试图过滤数组中的对象列表并显示它。过滤基于来自输入字段的用户输入。

我已经看过Stackoverflow上的一些问题,但我觉得这是不同的 - 因为我的数据已经在数组中了。 HTML:

<body ng-app="MyApp">
  <div ng-controller="MyCtrl">
    <form class="form-inline">
      <input ng-model="search" type="text"
        placeholder="Filter by" autofocus>
    </form>
    <div ng-repeat="f in feedbacklist | filter:search ">
      <div>{{f.jobId}}</div>
    </div>
  </div>
</body>

JS:

var app = angular.module("MyApp", []);

app.controller("MyCtrl", function($scope) {
$scope.search = "";
$scope.feedbacklist = [
                {
                    jobId: "1432",
                    feedbackId: "342342",
                    profileUrl: "assets/img/profiles/avatar_small2x.jpg",
                    address: "24 Mathers St, Smithswood",
                    name: "Jorem Ipsum",
                    initials: "JP",
                    content: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                    date: "23/05/2016",
                    message: "",
                    replies: [
                        {
                            jobId: "1232",
                            feedbackId: "342342",
                            profileUrl: "assets/img/profiles/avatar_small2x.jpg",
                            address: "24 Mathers St, Smithswood",
                            name: "Jorem Ipsum",
                            initials: "JP",
                            content: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                            date: "23/05/2016",
                        },
                        {
                            jobId: "1232",
                            feedbackId: "342342",
                            profileUrl: "assets/img/profiles/avatar_small2x.jpg",
                            address: "24 Mathers St, Smithswood",
                            name: "Jorem Ipsum",
                            initials: "JP",
                            content: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                            date: "23/05/2016",
                        }
                    ],

                },
                {
                    jobId: "1232",
                    feedbackId: "342342",
                    profileUrl: "",
                    address: "24 Mathers St, Smithswood",
                    name: "Jorem Ipsum",
                    initials: "JP",
                    content: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                    date: "23/05/2016",
                    message: "",
                    replies: [

                    ],

                },

            ];



});

我创造了一个小提琴here

1 个答案:

答案 0 :(得分:0)

此代码未发现您的代码存在任何问题。我唯一想知道的是你要过滤的对象中的哪个属性?

如果您想通过&#39; JobId&#39;过滤它?然后使用此代码 filter:{jobId:search}

Fiddle Link