【问题标题】:AngularJS : Searching for the equivalent string in an arrayAngularJS:在数组中搜索等效字符串
【发布时间】:2015-04-24 18:21:26
【问题描述】:

我想创建一个搜索过滤器,我想在其中搜索项目的状态。我的数据库中的状态是 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。

【问题讨论】:

  • 我在这里没有看到过滤器?

标签: c# asp.net-mvc angularjs


【解决方案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
                        }));
                    });
                }
            }
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 2012-12-18
    • 2023-03-13
    • 2011-07-22
    • 1970-01-01
    相关资源
    最近更新 更多