javascript - 在javascript中将项目插入数组

标签 javascript asp.net-web-api

我遇到了有关 JavaScript 的问题。具体来说,我有一个像这样的表

<table class="table">
    <tr>
        <th>
            <label>Select</label>
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FirstName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Middle)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LastName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DoB)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Gender)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.StartDate)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr id="@Html.DisplayFor(modelItem => item.EmployeeId)" ondblclick="DoubleClickOnRow(this)">
        <td>
            <input id="@Html.DisplayFor(modelItem => item.EmployeeId)" type="checkbox" onclick="SelectCheckBox(this)"/>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Middle)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LastName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DoB)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Gender)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.StartDate)
        </td>
    </tr>
}
</table>

我声明了一个数组来保存 EmployeeId,以检查一行第一列中的复选框。然而,它说arrayOfEmployeeId.push(id);不是一个函数。 顺便说一句,我想获取 EmployeeId 数组来在 ASP.NET Web api 中执行 DELETE 方法。我说得对吗?

var arrayOfEmployeeId = {};
function SelectCheckBox(thisRow)
    {
        var id = thisRow.id;
        arrayOfEmployeeId.push(id);
        console.log(arrayOfEmployeeId);
    }

最佳答案

arrayOfEmployeeId 是一个对象 ({})。您可能想要的是像 var arrayOfEmployeeId = []; 这样的数组。

关于javascript - 在javascript中将项目插入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36055787/

相关文章:

javascript - 将 Controller 添加到主体时,AngularJS 表达式停止工作

c# - 如何避免在 RESTful Web API 2 中执行不同的相同操作?

c# - 如何通过表单在 ASP.NET Web API 中实现 Active Directory 身份验证?

c# - HttpRequestMessage.GetClientCertificate() 在 Web API 中返回 null

javascript - 服务器上可编辑文件的安全性

javascript - 当 slider 更改和初始条件时如何获取当前数据 slider ?

javascript - 在 TinyMCE 编辑器中重复图案墙纸

javascript - 如何进行拖放操作?

c# - ASP.NET WebAPI 创建一级 JSON

javascript - 如何将 JS 对象集合发送到 ASP.NET API 服务?