我遇到了有关 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/