在ng-click调用上设置时未调用函数

时间:2016-11-03 01:26:20

标签: javascript angularjs button ng-controller

我的mvc应用程序中有以下视图和控制器。我有一个按钮(“获取过滤行”),我想在控制器中调用getFilteredRows()函数。我已经尝试了多个组合的东西来获取按钮来调用该函数,但我似乎无法通过按钮来调用它。我无法弄清楚为什么函数没有被按钮调用。帮助

@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

1 个答案:

答案 0 :(得分:2)

应该改为,

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