カスタムキー/値のペア形式でフォームをシリアル化する必要があります。カスタムキーと値のペアでフォームをシリアル化する方法は?
<form name="ltq_frm" id="ltq_frm">
<table class="table" id="licenses_to_quote">
<thead>
<tr>
<th>License ID</th>
<th>Quote ID</th>
<th>Agreement Type</th>
<th>Customer Site</th>
</tr>
</thead>
<tbody id="licenses_to_quote_body">
<tr data-id="96">
<td>
96
<input type="hidden" name="license_id" value="96">
</td>
<td>
<input class="hidden-select2-96" type="hidden" name="quote_id" value="249"> 249
</td>
<td>Percentage Support</td>
<td>Frito-Lay, Inc.</td>
</tr>
<tr data-id="100">
<td>
100
<input type="hidden" name="license_id" value="100">
</td>
<td>
<input class="hidden-select2-100" type="hidden" name="quote_id" value="">
</td>
<td>Percentage Support</td>
<td>Frito-Lay, Inc.</td>
</tr>
</tbody>
</table>
</form>
<button id="subm">
Click
</button>
そして、これは私がそれをシリアル化しています方法です:
$(function() {
$('#subm').click(function() {
var sA = $('#ltq_frm').serializeArray();
var s = $('#ltq_frm').serialize();
console.log(sA);
console.log(s);
});
});
これは「作業」ですが、私は、出力として4つの値の配列を取得していますこれは私のHTMLコードがどのように見えるかです。上記の値は、フォーム上の隠し要素、license_id
とquote_id
として挙げたものから来て
[
96 => 249,
100 =>
]
:上記の例を使用
[
'license_id' => 'quote_id'
]
:私のような何かを取得したいと思います。
私はhereをチェックしていましたが、私の値を必要なキー/値のペアに変換する方法がわかりませんでした。
This is jsFiddle私はあなたが必要な場合に備えて働いていました。
注:あなたはより良い提案を持っているか、私はそれを得る私は先に行く
私はこれらの値がどこから来るのかを教えなければならないと思います。'96 => 249'が必要ですが、' 96'はデータ属性にあり、ある値とクラス名の一部に、この値がどこから得られたのかは重要ですか? – adeneo
そうですね - > https://jsfiddle.net/kehxzq1L/3/ – adeneo
@adeneoはい、あなたも投票をします;) – ReynierPM