AngularJS:在数组中搜索等效字符串

时间:2015-04-22 03:27:50

标签: c# asp.net-mvc angularjs

我想制作一个搜索过滤器,其中我想搜索项目的状态。我的数据库中的状态是int,所以我做了每个索引的等价。

要解释更多,这是我的代码。

MVC控制器

public JsonResult GetStatusList()
    { 
        return Json(new string[] {
            ""
            ,"New"
            ,"Processing"
            ,"PR Approved"
            ,"Qouting"
            ,"Qouting Approved"
            ,"PO Processing"
            ,"Closed"
            ,"Cancelled"
            ,"Rejected"
            ,"PO Issued"
            ,"On Delivery"
            ,"Received"
            ,"AP Posting"
            ,"Payment"
            ,"Sourcing"
            ,"Re-Processing"
        },JsonRequestBehavior.AllowGet);
    }

这是我的MVC视图

 <tr data-ng-repeat="model in models  | orderBy: sorting:reverse | filter : filter ">

                    <td>{{jsonDatetotext(model.RequestDate) | date:'MM/dd/yyyy'}}</td>
                    <td>
                        <a href="#" data-toggle="modal" data-target="#basicModalContent" data-ng-click="getSelectedPR(model)">{{model.RequestID}}
                        </a>
                    </td>
                    <td>{{model.PARNumber }}</td>
                    <td>{{model.ProgramName }}</td>
                    <td>{{model.FullName }}</td>
                    <td>{{model.DepartmentName | uppercase}}</td>
                    <td>{{model.PONo}}</td>
                    **<td>{{StatusList[model.StatusID] | uppercase}}</td>**
                    <td class="totalAmount"><span class="pull-right">{{model.TotalAmount | number:2}}</span>
                    </td>
                    <td>{{model.InboxLearUID | lowercase}}</td>
                </tr>

我想要包含搜索过滤器的状态。状态只能按其ID进行搜索。

这是我的角色

 scope.getStatus = http.get('GetStatusList').success(function (status) {
            scope.StatusList = status;
        });

我希望状态本身不仅会被搜索到它的ID。

1 个答案:

答案 0 :(得分:1)

尝试在角度上添加此项。 我建议你使用复选框进行项目。

    scope.array_ = angular.copy(scope.array);
        scope.getStatus = http.get('GetStatusList').success(function (status) {
            scope.StatusList = status;

        });


        PRApp.directive("checkboxGroup", function () {
            return {
                restrict: "A",
                link: function (scope, elem, attrs) {
                    // Determine initial checked boxes
                    if (scope.array.indexOf(scope.item.id) !== -1) {
                        elem[0].checked = true;
                    }

                    // Update array on click
                    elem.bind('click', function () {
                        var index = scope.array.indexOf(scope.item.id);
                        // Add if checked
                        if (elem[0].checked) {
                            if (index === -1) scope.array.push(scope.item.id);
                        }
                            // Remove if unchecked
                        else {
                            if (index !== -1) scope.array.splice(index, 1);
                        }
                        // Sort and update DOM display
                        scope.$apply(scope.array.sort(function (a, b) {
                            return a - b
                        }));
                    });
                }
            }
        });