How to add multiple items? #1708
Answered
by
EmilTholin
thanksyouall
asked this question in
Q&A
-
I know how to add one item: .put(cast({...})). Call put () every time or is there a better way?
|
Beta Was this translation helpful? Give feedback.
Answered by
EmilTholin
Apr 28, 2021
Replies: 1 comment 1 reply
-
Hi @thanksyouall! You can use the const MyModel = types
.model({
members: types.map(Member)
})
.actions((self) => ({
someAction(members: any) {
self.members.merge(members);
}
}));
const myModel = MyModel.create({
members: {
"1": {
id: "1",
name: "foo"
},
"2": {
id: "2",
name: "bar"
}
}
});
myModel.someAction({
"3": { id: "3", name: "baz" },
"4": { id: "4", name: "quz" }
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
thanksyouall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @thanksyouall!
You can use the
merge
method: