teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

書式の改善

2017/05/30 18:10

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -46,23 +46,21 @@
46
46
  37780
47
47
  以下javascript
48
48
  ____________________________________________________________________
49
- $(function(){
50
- $("#completion").click(function(){
49
+ $(document).ready(function() {
50
+ $(document).on('click',"#completion",function(){
51
+ alert("kurikku")
51
52
  var user = JSON.parse(sessionStorage.getItem("user"));
52
53
  var list = JSON.parse(sessionStorage.getItem("cart"));
53
54
  var subtotal = sessionStorage.getItem("subtotal");
54
- var users = {
55
+ var users = {
55
- "userid": user.user_id,
56
+ "userid": user.user_id,
56
- "subtotal": subtotal,
57
+ "subtotal": subtotal,
57
- "products":
58
+ "products":
58
- [
59
+ [
59
- {
60
+ {
60
- "productid": list.productid,
61
+ "productid": list[i].productid,
61
- "quantity": list.quantity
62
+ "quantity": list[i].quantity
62
- }
63
+ }
63
- ]
64
+ ]
64
- }
65
+ }
65
- ```
66
- }
67
- ;sessionStorage.setItem("users", JSON.stringify(users));
68
66
  ```

2

文法修正、JSON書式改善、エラー一つ改善

2017/05/30 18:10

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,13 @@
1
- こんばんは、セッションストレージからデータを取得してJSON形式にしたいのですが、"productid"と
1
+ こんばんは、セッションストレージからデータを取得してJSON形式にしたいのですが、配列になっている"productid"と"quantity"に複数の値をいれる方法がわかりません。
2
+ 形としては [{
3
+ "productid": list.productid,
2
- "quantity"に複数の値をいれる方法がわかりません。
4
+ "quantity": list.quantity
5
+ },
6
+ {
7
+ "productid": list.productid,
3
- また"subtotal": subtotalとしているのですが使用できないstringだと怒られます。
8
+ "quantity": list.quantity
4
- var subtotal = sessionStorage.getItem("subtotal");
9
+ }]
5
- で扱えるようなっとはおもです。。
10
+ 配列の中複数の値を持てるしたいです。
6
11
  お力添えいただけるとうれしいです。
7
12
  ```ここに言語を入力
8
13
  以下セッションストレージ
@@ -46,15 +51,17 @@
46
51
  var user = JSON.parse(sessionStorage.getItem("user"));
47
52
  var list = JSON.parse(sessionStorage.getItem("cart"));
48
53
  var subtotal = sessionStorage.getItem("subtotal");
49
- var users = {
54
+ var users = {
50
- "userid": user.user_id,
55
+ "userid": user.user_id,
56
+ "subtotal": subtotal,
57
+ "products":
51
- [ {
58
+ [
59
+ {
52
- "productid" : list.productid,
60
+ "productid": list.productid,
53
- "quantity" : list.quantity
61
+ "quantity": list.quantity
54
- }
62
+ }
55
- ]
63
+ ]
56
- ```ここに言語を入力
64
+ }
57
- "subtotal": subtotal
58
65
  ```
59
66
  }
60
67
  ;sessionStorage.setItem("users", JSON.stringify(users));

1

書式の改善

2017/05/30 16:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -9,12 +9,34 @@
9
9
  _________________________________________________________________
10
10
  cart json
11
11
  [
12
+ {
13
+ "id": "1",
12
- {"title":"パーカー","price":"10000","id":"1","manufacture":"mont-bell","quantity":2},
14
+ "manufacture": "mont-bell",
15
+ "price": "10000",
16
+ "quantity": 2,
17
+ "title": "パーカー"
18
+ },
19
+ {
20
+ "id": "3",
13
- {"title":"ジャケット","price":"13924","id":"3","manufacture":"Marmot","quantity":1},
21
+ "manufacture": "Marmot",
22
+ "price": "13924",
23
+ "quantity": 1,
24
+ "title": "ジャケット"
25
+ },
26
+ {
27
+ "id": "4",
14
- {"title":"S/S","price":"3856","id":"4","manufacture":"THE","quantity":1}
28
+ "manufacture": "THE",
29
+ "price": "3856",
30
+ "quantity": 1,
31
+ "title": "S/S"
32
+ }
15
33
  ]
16
34
  user json
35
+ {
36
+ "user_id": "2",
37
+ "user_name": "hoge",
17
- {"user_id":"2","user_name":"hoge","user_zip_code":"231-8359"}
38
+ "user_zip_code": "231-8359"
39
+ }
18
40
  subtotal
19
41
  37780
20
42
  以下javascript