在 UI 中传递对象 属性-Grid 出现未定义错误

Passing Object Property in UI-Grid Getting Undefined Error

在 UI 网格中传递对象 属性 时遇到问题。

我试图通过使用 UI-Grid 中的 cellTemplete 选项将一个对象 属性 传递给一个函数,但是我遇到了一个未定义的错误。

我能够将索引传递给函数,但不是行数据的实际 属性。

如何通过 deleteMember 函数获取对象 属性?

vm.TeamMembersGridOptions = {
    enableGridMenu: false,
    enableSorting: true,
    enableHorizontalScrollbar: 0, /*always hide horizontal scroll bar*/
    enableVerticalScrollbar: 1, /*always show vertical scroll bar*/
    rowHeight: 40,
    minRowsToShow: 5,
    columnDefs: [
        {
            enableHiding: false,
            enableColumnMenu: false,
            width: '10%',
            field: 'edit',
            cellClass: 'ui-grid-cell-contents',
            cellTemplate:
                '<a class="ui-action-type-mouse" ng-click="grid.appScope.vm.deleteMember(rowRenderIndex, row.entity.member)" title="Delete"><img src="resources/images/fa_remove.png"></img></a>'
        },
        data: vm.teamMembers
    ]

function deleteMember(idx, member) {
    console.log(member);
    var params = {
        member: vm.teamMembers[idx]
    };
    var user = params.member.userProfile;
    var current = params.member.current;
    var messageText;
    var headerText;
    if (!current) {
        messageText = "Are you sure you want to delete this user: " + user.firstName + " " + user.lastName + "(" + user.email + ")?";
        headerText = "Delete Team Member?";
    }
    else {
        messageText = "Are you sure you want to delete yourself from this team? You will no longer be able to access this project if you continue.";
        headerText = "Delete Yourself?";
    }
}  
<div ng-if="!vm.loadingTeam" ui-grid="vm.TeamMembersGridOptions" ui-grid-auto-resize></div>

您正在将 vm.teamMembers 传递给网格。所以 vm.teamMembers 数组中的每一项在 cellTemplate.

中都是 row.entity

尝试只传入 row.entity 而不是 row.entity.members.