回答編集履歴
7
テキスト修正
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
```diff
|
8
8
|
- constructor(user: User) {
|
9
9
|
+ constructor(user: User, isShow: boolean = false) {
|
10
|
-
this.userCode =user.code
|
10
|
+
this.userCode = user.code
|
11
11
|
this.userName = user.name
|
12
12
|
this.title = user.title
|
13
13
|
this.body = user.body
|
6
テキスト修正
answer
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
- constructor(user: User) {
|
9
9
|
+ constructor(user: User, isShow: boolean = false) {
|
10
10
|
this.userCode =user.code
|
11
|
-
this.userName = user.
|
11
|
+
this.userName = user.name
|
12
12
|
this.title = user.title
|
13
13
|
this.body = user.body
|
14
14
|
+ this.isShow = isShow
|
5
テキスト修正
answer
CHANGED
@@ -42,4 +42,4 @@
|
|
42
42
|
```
|
43
43
|
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012](https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012)
|
44
44
|
|
45
|
-
なお、追記した別案のほうのコードだと、型エラーにはならない(__と思います。__)ですが、追加されるオブジェクトが、UserEntityクラスのインスタンスではなく普通のオブジェクトになってしまうので、usersEntities の要素を UserEntityクラスの
|
45
|
+
なお、追記した別案のほうのコードだと、型エラーにはならない(__と思います。__)ですが、追加されるオブジェクトが、UserEntityクラスのインスタンスではなく普通のオブジェクトになってしまうので、usersEntities の要素を UserEntityクラスのインスタンスに揃えたいのであれば、回答のはじめに書いたほうのコードのほうがよいかと思います。
|
4
テキスト追加
answer
CHANGED
@@ -40,4 +40,6 @@
|
|
40
40
|
- this.usersEntities = [...this.usersEntities, new UserEntity(user)]
|
41
41
|
+ this.usersEntities = [...this.usersEntities, { ...new UserEntity(user), isShow: true }]
|
42
42
|
```
|
43
|
-
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012](https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012)
|
43
|
+
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012](https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012)
|
44
|
+
|
45
|
+
なお、追記した別案のほうのコードだと、型エラーにはならない(__と思います。__)ですが、追加されるオブジェクトが、UserEntityクラスのインスタンスではなく普通のオブジェクトになってしまうので、usersEntities の要素を UserEntityクラスのエンティティに揃えたいのであれば、回答のはじめに書いたほうのコードのほうがよいかと思います。
|
3
テキスト修正
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
以下の修正でいかがでしょう?
|
3
3
|
|
4
4
|
|
5
|
-
**(1)** `class UserEntity` の constructor に省略可能な引数 `isShow` を追加
|
5
|
+
**(1)** `class UserEntity` の constructor に省略可能な引数 `isShow` を追加して、`this.isShow` に代入
|
6
6
|
|
7
7
|
```diff
|
8
8
|
- constructor(user: User) {
|
2
テキスト追加
answer
CHANGED
@@ -29,4 +29,15 @@
|
|
29
29
|
上記のサンプルでは、オブジェクト `obj` に`usersEntities`プロパティと`addOffers`メソッドを持たせて、`obj.addOffers` で2つの`User`を含む配列 `[ userB, userC ]`を渡しています。その結果、`obj.usersEntities` には2つの要素が追加されますが、それらの `isShow` は true になっていることを確認できます。
|
30
30
|
|
31
31
|
|
32
|
-
以上、参考になれば幸いです。
|
32
|
+
以上、参考になれば幸いです。
|
33
|
+
|
34
|
+
|
35
|
+
### 追記
|
36
|
+
|
37
|
+
別案を挙げます。以下のようにすれば、`UserEntity` のconstructorを修正せずに、`addOffers`のみの修正で済ませることもできます。
|
38
|
+
|
39
|
+
```diff
|
40
|
+
- this.usersEntities = [...this.usersEntities, new UserEntity(user)]
|
41
|
+
+ this.usersEntities = [...this.usersEntities, { ...new UserEntity(user), isShow: true }]
|
42
|
+
```
|
43
|
+
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012](https://codepen.io/jun68ykt/pen/GRpYWqr?editors=0012)
|
1
テキスト修正
answer
CHANGED
@@ -22,4 +22,11 @@
|
|
22
22
|
+ this.usersEntities = [...this.usersEntities, new UserEntity(user, true)]
|
23
23
|
```
|
24
24
|
|
25
|
+
以下は上記のコードを試すサンプルです。
|
26
|
+
|
27
|
+
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/NWGOdOj?editors=0012](https://codepen.io/jun68ykt/pen/NWGOdOj?editors=0012)
|
28
|
+
|
29
|
+
上記のサンプルでは、オブジェクト `obj` に`usersEntities`プロパティと`addOffers`メソッドを持たせて、`obj.addOffers` で2つの`User`を含む配列 `[ userB, userC ]`を渡しています。その結果、`obj.usersEntities` には2つの要素が追加されますが、それらの `isShow` は true になっていることを確認できます。
|
30
|
+
|
31
|
+
|
25
32
|
以上、参考になれば幸いです。
|