admin管理员组

文章数量:1352828

I defined a mobx map as below:

@observable editors = observable.map();

then I added object on the editors as below:

  editors.set(key, {
    alias: 'alias-1',
    message: 'hello',
  })

when I get the object from editor as below:

  let myEditor = editors.get(key)

the returned object myEditor has some builtin functions such as:

$mobx:ObservableObjectAdministration
get alias:function ()
set alias:function ()
get message:function ()
set message:function ()

I wander how I can get a plain javascript object from editor?

I defined a mobx map as below:

@observable editors = observable.map();

then I added object on the editors as below:

  editors.set(key, {
    alias: 'alias-1',
    message: 'hello',
  })

when I get the object from editor as below:

  let myEditor = editors.get(key)

the returned object myEditor has some builtin functions such as:

$mobx:ObservableObjectAdministration
get alias:function ()
set alias:function ()
get message:function ()
set message:function ()

I wander how I can get a plain javascript object from editor?

Share Improve this question edited Apr 12, 2017 at 8:40 Tholle 113k22 gold badges208 silver badges197 bronze badges asked Apr 12, 2017 at 5:55 Joey Yi ZhaoJoey Yi Zhao 42.8k87 gold badges357 silver badges661 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You can use toJS.

Example

class MyStore {
  @observable editors = observable.map({});
}

const myStore = new MyStore();

myStore.editors.set('example', {
  alias: 'alias-1',
  message: 'hello'
});

console.log(toJS(myStore.editors));

本文标签: javascriptHow to get a plain object from mobx objectStack Overflow