0

私のアプリケーションでは、店舗データベースで注文を追跡できます。notesこのデータベースには、に接続されているために使用される弱いエンティティが含まれていorderIDます。ユーザーが同時に多くの注文に同じ「メモ」を適用できるようにしたいのですが、テーブルには販売にnotes依存するフィールドがいくつかあります。locationつまり、すべての販売場所が同じ場合にのみ、同じメモを適用できるようにする必要があります。

簡易表示:

@using (Html.BeginForm("Create", "Note", FormMethod.Get, new { name = "editForm" }))
{
    <table id="DataTable">
        <tr>
            <th>
                <input type="button" value="Edit" onclick="checkboxValidation()"/>
            </th>
            <th>
                @Html.DisplayNameFor(model => model.OrderID)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.location)
            </th>
        </tr>
@foreach (var item in Model)
{   
    <tr >
        <td>
            <input type="checkbox" name="ids" value="@item.orderID" />
        </td>
    <td>
        @Html.ActionLink(item.OrderID.ToString(), "Details", "Search", new { orderID = item.orderID.ToString() }, null)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.location)
    </td>
    </tr>
}
</table>

checkboxValidation()少なくとも1つのチェックボックスがチェックされているかどうかを確認するために私が書いたjavascript関数です。チェックされた行のすべての場所が同じであることを確認するには、どうすればチェックを追加できますか? これは可能ですか?ありがとう

編集:詳細を見逃しました。編集ボタンをクリックすると、チェックが成功するとフォームが送信され、notesエディターが表示されます。

4

1 に答える 1

1

JQuery を使用すると、かなり簡単なはずです。

// find all the checked rows
var checkedItems = $("#DataTable").find("tr td input[type=checkbox]");

// construct a locations array for all checked items
var locations = [];
checkedItems.each(function(index, element) {
    if ($(element).is(":checked")) {
        locations.push($(this).closest("td").next("td").next("td").text().trim());
    }
});

// confirm each location is the same
var valid = true;
locations.each(function(index, element) {
    if (index > 0 && locations[index-1] != element) {
        valid = false;
        return;
    }
});

あなたがやりたいと思うかもしれないもう1つのことは、trtd要素にいくつかのデータタグを追加することです。これにより、小さなUIの再配置で壊れない、より堅牢なセレクターを作成できます(tr[data-role=check]andtr[data-role=location]など)。


( JQuery closestおよびJQuery eachを使用します。)

于 2012-12-10T20:32:20.953 に答える