回答編集履歴

7

テキスト修正

2020/05/17 01:11

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  + constructor(user: User, isShow: boolean = false) {
18
18
 
19
- this.userCode =user.code
19
+ this.userCode = user.code
20
20
 
21
21
  this.userName = user.name
22
22
 

6

テキスト修正

2020/05/17 01:11

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  this.userCode =user.code
20
20
 
21
- this.userName = user.user.name
21
+ this.userName = user.name
22
22
 
23
23
  this.title = user.title
24
24
 

5

テキスト修正

2020/05/17 01:10

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -86,4 +86,4 @@
86
86
 
87
87
 
88
88
 
89
- なお、追記した別案のほうのコードだと、型エラーにはならない(__と思います。__)ですが、追加されるオブジェクトが、UserEntityクラスのインスタンスではなく普通のオブジェクトになってしまうので、usersEntities の要素を UserEntityクラスのティティに揃えたいのであれば、回答のはじめに書いたほうのコードのほうがよいかと思います。
89
+ なお、追記した別案のほうのコードだと、型エラーにはならない(__と思います。__)ですが、追加されるオブジェクトが、UserEntityクラスのインスタンスではなく普通のオブジェクトになってしまうので、usersEntities の要素を UserEntityクラスのスタンスに揃えたいのであれば、回答のはじめに書いたほうのコードのほうがよいかと思います。

4

テキスト追加

2020/05/16 12:38

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -83,3 +83,7 @@
83
83
  ```
84
84
 
85
85
  - **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012](https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012)
86
+
87
+
88
+
89
+ なお、追記した別案のほうのコードだと、型エラーにはならない(__と思います。__)ですが、追加されるオブジェクトが、UserEntityクラスのインスタンスではなく普通のオブジェクトになってしまうので、usersEntities の要素を UserEntityクラスのエンティティに揃えたいのであれば、回答のはじめに書いたほうのコードのほうがよいかと思います。

3

テキスト修正

2020/05/16 12:09

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- **(1)** `class UserEntity` の constructor に省略可能な引数 `isShow` を追加
9
+ **(1)** `class UserEntity` の constructor に省略可能な引数 `isShow` を追加して、`this.isShow` に代入
10
10
 
11
11
 
12
12
 

2

テキスト追加

2020/05/16 11:24

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -61,3 +61,25 @@
61
61
 
62
62
 
63
63
  以上、参考になれば幸いです。
64
+
65
+
66
+
67
+
68
+
69
+ ### 追記
70
+
71
+
72
+
73
+ 別案を挙げます。以下のようにすれば、`UserEntity` のconstructorを修正せずに、`addOffers`のみの修正で済ませることもできます。
74
+
75
+
76
+
77
+ ```diff
78
+
79
+ - this.usersEntities = [...this.usersEntities, new UserEntity(user)]
80
+
81
+ + this.usersEntities = [...this.usersEntities, { ...new UserEntity(user), isShow: true }]
82
+
83
+ ```
84
+
85
+ - **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012](https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012)

1

テキスト修正

2020/05/16 10:59

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -46,4 +46,18 @@
46
46
 
47
47
 
48
48
 
49
+ 以下は上記のコードを試すサンプルです。
50
+
51
+
52
+
53
+ - **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/NWGOdOj?editors=0012](https://codepen.io/jun68ykt/pen/NWGOdOj?editors=0012)
54
+
55
+
56
+
57
+ 上記のサンプルでは、オブジェクト `obj` に`usersEntities`プロパティと`addOffers`メソッドを持たせて、`obj.addOffers` で2つの`User`を含む配列 `[ userB, userC ]`を渡しています。その結果、`obj.usersEntities` には2つの要素が追加されますが、それらの `isShow` は true になっていることを確認できます。
58
+
59
+
60
+
61
+
62
+
49
63
  以上、参考になれば幸いです。