在 javascript 中将项目推送到数组中
Pushing an item into array in javascript
我遇到了关于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 = [];
这样的数组。
arrayOfEmployeeId = {}; 是一个对象你可以把它变成一个数组。
arrayOfEmployeeId = [];您可以使用拼接方法根据需要删除。
相关文章:
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 按不同项目对对象数组进行排序
- 使用JavaScript或jQuery检查单选按钮选择是否与数组中的项目匹配
- JS:从整个数组中每次得到5个项目,并得到平均值
- 使用圆中的数组更改背景颜色项目
- 编辑CSV数组中的项目-快速CSV node.js
- 我可以限制我添加到数组中的项目数量吗
- 使用javascript/jquery从现有数组中创建一个新数组,该数组保存项目存在的次数
- 什么's JavaScript数组中项目的作用域
- 将项目放入数组中
- 使用 id 和 Javascript 从数组中删除项目
- (角度.js)如何通过过滤器计算数组中有多少项目
- 如何通过迭代对象数组来删除某些项目
- Lodash 从与值数组不匹配的数组中获取项目
- 发布要形成的 n 个项目的数组
- 查找数组中项目包含子字符串的索引
- 我怎么能只保留符合特定条件的数组项目
- 关于将数组项目处理为分区的问题
- Php回显数组项目逐个点击(唯一)
- 连续删除数组项目(游戏障碍)