0

私はそのようなものに見えるテーブルを持っています

<table id="grid" class="table table-bordered table-hover table-inline">
    <thead>
        <tr>
            <th>Id</th>
            <th>Dropdown List</th>
            <th><input id="selectAll" type="checkbox" /></th>
        </tr>
    </thead>
    <tbody data-bind="foreach: stuff
        <tr>
            <td data-bind="text: someId"></td>
            <td>
                <select class="input-medium" data-bind="options: someStuff, optionsText:'DisplayName', optionsValue:'StandardCode'"></select>                           
            </td>
            <td>
                <input type="checkbox" data-bind="value: someId"/>
            </td>
        </tr>
    </tbody>
</table>

次に、JavaScriptを使用して、このように選択した行を繰り返し処理します

$('grid input[type="checkbox"]:checked').each(function () {

    var someSelectedId= $(this).val();

    var dropDownlistValue= ??       
});

ノックアウトを使用して、データをテーブルとドロップダウンにバインドしています。

行を反復処理しているときに、各行のドロップダウンリストで選択した値を取得するにはどうすればよいですか?私の人生のために、私はそれを理解できないようです。ありがとう!

4

2 に答える 2

2

使用する:

var dropDownlistValue = $(this).parent().prev().find('select.input-medium').val();
于 2013-03-20T14:30:55.293 に答える
2

または...

$(this).closest("tr").find("select.input-medium").val();

AVの方法はおそらく高速ですが、TRに移動すると、行のどこにいても選択が見つかるため、柔軟性が高まります。

于 2013-03-20T14:36:16.770 に答える