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

質問編集履歴

3

説明の修正

2020/05/21 10:03

投稿

j-nagnn
j-nagnn

スコア21

title CHANGED
File without changes
body CHANGED
@@ -62,7 +62,7 @@
62
62
  }
63
63
  }
64
64
  ```
65
- 'json.data'の内容】
65
+ gntの内容】
66
66
  [{"id":1,"text":"project #1","start_date":"2020-05-06","end_date":"2020-05-26","user":3,"duration":20,"parent":0,"progress":0},
67
67
  {"id":2,"text":"Task #1","start_date":"2020-05-06","end_date":"2020-05-16","user":0,"duration":10,"parent":1,"progress":0},
68
68
  {"id":3,"text":"Task #2","start_date":"2020-05-16","end_date":"2020-05-26","user":0,"duration":10,"parent":1,"progress":0}]

2

json.dataの内容をテキストベースに直しました

2020/05/21 10:03

投稿

j-nagnn
j-nagnn

スコア21

title CHANGED
File without changes
body CHANGED
@@ -62,4 +62,7 @@
62
62
  }
63
63
  }
64
64
  ```
65
- ![イメージ説明](2368a47bf70f8792064640df074af09e.png)
65
+ 【'json.data'の内容】
66
+ [{"id":1,"text":"project #1","start_date":"2020-05-06","end_date":"2020-05-26","user":3,"duration":20,"parent":0,"progress":0},
67
+ {"id":2,"text":"Task #1","start_date":"2020-05-06","end_date":"2020-05-16","user":0,"duration":10,"parent":1,"progress":0},
68
+ {"id":3,"text":"Task #2","start_date":"2020-05-16","end_date":"2020-05-26","user":0,"duration":10,"parent":1,"progress":0}]

1

コード部分を見やすいように変更しました。読み込みたいjsonファイル内容の画像を添付しました。

2020/05/21 09:56

投稿

j-nagnn
j-nagnn

スコア21

title CHANGED
File without changes
body CHANGED
@@ -11,50 +11,55 @@
11
11
  使用ツール:DHTMLX Gantt (URL:https://docs.dhtmlx.com/gantt/ )
12
12
 
13
13
  【コード】
14
- [index.cshtml(View)]
14
+ <index.cshtml>
15
+ ```Javascript
15
- <script type="text/javascript" >
16
+ <script type="text/javascript" >
16
- function jsonExport() {
17
+ function jsonExport() {
17
- var json = new Object();
18
+ var json = new Object();
18
- json = gantt.serialize('json');
19
+ json = gantt.serialize('json');
19
- var gnt = JSON.stringify(json.data);
20
+ var gnt = JSON.stringify(json.data);
20
- alert(gnt);
21
+ alert(gnt);
21
- var aj = '@Url.Action("JSONTest")';
22
+ var aj = '@Url.Action("JSONTest")';
22
23
 
23
-
24
- $.ajax(
24
+ $.ajax(
25
- {
25
+ {
26
- type: 'POST',
26
+ type: 'POST',
27
- url: aj,
27
+ url: aj,
28
- data: gnt,
28
+ data: gnt,
29
- dataType: 'json',
29
+ dataType: 'json',
30
- contentType: 'application/json',
30
+ contentType: 'application/json',
31
-
32
- error: function () { },
33
- complete: function (data) { alert(data.responseText) }
34
- }
35
- );
36
- }
37
- </script>
38
31
 
32
+ error: function () { },
33
+ complete: function (data) { alert(data.responseText) }
34
+ }
35
+ );
36
+ }
37
+ </script>
38
+ ```
39
39
  [HomeControllers.cs]
40
+ ```C#
40
- public ActionResult JSONTest(Data viewModel,Object son)
41
+ public ActionResult JSONTest(Data viewModel,Object son)
41
- {
42
+ {
42
-        string[] vs = new string[4];
43
+ string[] vs = new string[4];
43
- vs[0] = viewModel.Text;
44
+ vs[0] = viewModel.Text;
44
- vs[1] = viewModel.StartDate.ToString();
45
+ vs[1] = viewModel.StartDate.ToString();
45
- vs[2] = viewModel.EndDate.ToString();
46
+ vs[2] = viewModel.EndDate.ToString();
46
- vs[3] = viewModel.Duration.ToString();
47
+ vs[3] = viewModel.Duration.ToString();
47
- return Json(vs);
48
+ return Json(vs);
48
- }
49
+ }
50
+ ```
49
51
  [Data.cs(Model)]
52
+ ```C#
50
53
  namespace GantDHT.Models
51
54
  {
52
- public class Data {
55
+ public class Data {
53
56
 
54
- public int Id { get; set; }
57
+ public int Id { get; set; }
55
- public string Text { get; set; }
58
+ public string Text { get; set; }
56
- public DateTime StartDate { get; set; }
59
+ public DateTime StartDate { get; set; }
57
- public DateTime EndDate { get; set; }
60
+ public DateTime EndDate { get; set; }
58
- public int Duration { get; set; }
61
+ public int Duration { get; set; }
59
- }
62
+ }
60
- }
63
+ }
64
+ ```
65
+ ![イメージ説明](2368a47bf70f8792064640df074af09e.png)