ウェブサイトにカートがあり、ユーザーがカートにあるアイテムの数量を一度に簡単に変更できるようにする必要があります。
これが私がこれまでに持っているjavascriptコードです:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
var items = [];
$(".item").each(function () {
var productKey = $(this).find("input[type='hidden']").val();
var productQuantity = $(this).find("input[type='text']").val();
items.addKey(productKey, productQuantity); ?
});
// 1. Grab the values of each ammount input and it's productId.
// 2. Send this dictionary of key pairs to a JSON action method.
// 3. If results are OK, reload this page.
});
</script>
私が書いたコメントは、私がどのように進めるかについての単なるガイドラインです。
ある種の配列にキー/ペア要素を追加する方法はありますか?キーと値が必要なだけです。特別なことは何もありません。
addKey()
達成したいことを示すために、説明のためだけにメソッドを作成しました。