我收到了有關JavaScript的問題。 Specificly,我有這樣在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>
一個表,我宣佈一個陣列,從檢查的行的第一列中的複選框持有僱員。但是,它說arrayOfEmployeeId.push(id);不是功能。 順便說一句,我想獲得EmployeeId數組來執行ASP.NET web api中的DELETE方法。我對嗎?
var arrayOfEmployeeId = {};
function SelectCheckBox(thisRow)
{
var id = thisRow.id;
arrayOfEmployeeId.push(id);
console.log(arrayOfEmployeeId);
}
'var arrayOfEmployeeId = {}'不是數組,而是一個對象,你必須這樣做:'var arrayOfEmployeeId = [];' – cl3m
是的,這是完全正確的。 – Kramer