简体   繁体   English

设置为ng-click调用时未调用该函数

[英]function not being called when set up on a ng-click call

I have the following view and controller in my mvc app. 我的mvc应用程序中具有以下视图和控制器。 I have a button ("Get Filtered Rows") that I want to call the getFilteredRows() function in the controller. 我有一个按钮(“获取过滤的行”),我想在控制器中调用getFilteredRows()函数。 I have tried multiple combos of stuff to get the button to call the function, but I cant seem to get the button to call it. 我已经尝试了多种方法来获得按钮来调用函数,但是我似乎无法获得按钮来调用它。 I cannot figure out why the function is not being called by the button. 我无法弄清楚为什么按钮没有调用该函数。 Help? 救命?

@using ProjectExplorer.Web.Helpers
@model ProjectExplorer.Web.ViewModels.IProjectHeaderViewModel

@{
    var projects = Model.ProjectHeaders;
}

<div>
    <div class="projectlist" ng-controller="MatchingProjectsController as vm"
         ng-init='vm.init(@Html.JsonFor(projects))'>
        <h3>Matching Projects</h3>
        @Html.ActionLink("Export to Excel", "ExcelExport")
        <button ng-click="getFilteredRows()">Get Filtered Rows</button>
        <div id="projectsGrid" ui-grid="vm.projectsTableData" ui-grid-resize-columns ui-grid-selection class="grid gridlist"></div>
    </div>
</div>


(function () {
    "use strict";
    window.app.controller("MatchingProjectsController", MatchingProjectsController);
    function MatchingProjectsController(uiGridConstants) {
        var vm = this;
        vm.init = init;
        function init(projects) {
            vm.projects = projects;
            vm.projectsTableData = _.map(projects, _.partialRight(_.pick, "projectId", "projectServiceNumber", "location", "name", "country", "completionYear", "totalAreaSquareFeet", "totalAreaSquareMeters", "constructionCost", "constructionStatusName", "hasImagery"));
            vm.projectsTableData = {
                enableColumnSorting: true,
                enableFiltering: true,
                enableVerticalScrollbar: false,
                columnDefs: [
                    {
                        field: "projectServiceNumber", name: "Number", width: "6%",
                        cellTemplate: "<div class='text-center ui-grid-cell-contents'>" +
                            "<a href=Details/{{row.entity.projectId}}>{{COL_FIELD}}</a>" +
                            "</div>" },
                    {
                        field: "name", width: "27%",
                        cellTemplate: "<div class='ui-grid-cell-contents'>" +
                            "<a href=Details/{{row.entity.projectId}}>{{COL_FIELD}}</a>" +
                            "</div>"
                    },
                    { field: "location", width: "12%" },
                    { field: "country", width: "8%" },
                    {
                        field: "completionYear", filters: [
                            {
                                condition: uiGridConstants.filter.GREATER_THAN_OR_EQUAL,
                                placeholder: "after"
                            },
                            {
                                condition: uiGridConstants.filter.LESS_THAN_OR_EQUAL,
                                placeholder: "before"
                            }
                        ], name: "Construction Year", width: "8%" },
                    {
                        field: "totalAreaSquareFeet", filters: [
                            {
                                condition: uiGridConstants.filter.GREATER_THAN_OR_EQUAL,
                                placeholder: "greater than"
                            },
                            {
                                condition: uiGridConstants.filter.LESS_THAN_OR_EQUAL,
                                placeholder: "less than"
                            }
                        ], name: "Square Feet", width: "8%", cellTemplate: '<div class="text-center ui-grid-cell-contents">{{ COL_FIELD | number:0 | hide_zero }}</div>' },
                    {
                        field: "totalAreaSquareMeters", filters: [
                            {
                                condition: uiGridConstants.filter.GREATER_THAN_OR_EQUAL,
                                placeholder: "greater than"
                            },
                            {
                                condition: uiGridConstants.filter.LESS_THAN_OR_EQUAL,
                                placeholder: "less than"
                            }
                        ], name: "Square Meters", width: "8%", cellTemplate: '<div class="text-center ui-grid-cell-contents">{{ COL_FIELD | hide_zero | number:0 }}</div>' },
                    {
                        field: "constructionCost", filters: [
                            {
                                condition: uiGridConstants.filter.GREATER_THAN_OR_EQUAL,
                                placeholder: "greater than"
                            },
                            {
                                condition: uiGridConstants.filter.LESS_THAN_OR_EQUAL,
                                placeholder: "less than"
                            }
                        ], displayName: "Cost (USD)", width: "8%", cellTemplate: '<div class="text-center ui-grid-cell-contents">{{ COL_FIELD | hide_zero | currency:undefined:0 }}</div>' },
                    { field: "constructionStatusName", width: "8%", name: "Construction Status" },
                    {
                        field: 'hasImagery',
                        name: "Imagery",
                        width: '6%',
                        enableFiltering: false,
                        cellTemplate: '<div ng-show="COL_FIELD" class="text-center ui-grid-cell-contents"><span class="glyphicon glyphicon-ok"></span></div>' }
                ],
                enableColumnMenus: false,
                exporterMenuPdf: false,
                data: vm.projectsTableData,
                onRegisterApi: function (gridApi) {
                    vm.gridApi = gridApi;
                }
            };
        }
        vm.filteredRows = [];
        vm.getFilteredRows = function () {
            var _renderedRows = vm.gridApi.grid.renderContainers.body.renderedRows;
            vm.filteredRows = vm.gridApi.core.getVisibleRows(vm.gridApi.grid);
        };
    }
})();
//# sourceMappingURL=MatchingProjectsController.js.map

它应该更改为

<button ng-click="vm.getFilteredRows()">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM