2017-03-05 59 views
1

我读here这是可能访问使用点符号Record对象的道具像person.Name X person.get(“名称”)。但是,如果我尝试直接使用属性访问它,它并不适用于我。使用点标记访问Immutable.js记录

我的代码:

new Record({ 
    id: 123, 
    description: 'Foo', 
    imgSrc: 'https://foo.co' 
})) 

如果我尝试访问属性描述直接像person.description这是行不通的。我应该使用person.get('description')而不是直接访问它。

我做错了,因为它应该让我直接访问属性?

回答

2

您是使用地图,但使用点符号进行属性访问仅在Immutable.Record上可用。这里是网站上的相关部分:https://facebook.github.io/immutable-js/docs/#/Record

//first make a template 
var MyThingie = Record({id:123, description:'Foo', imgSrc: 'https://foo.co'}); 
//now create records 
var myRecord = new MyThingie({description:'Not the default description'}); 
//outputs 'Not the default description' 
console.log(myRecord.description); 
+0

Yeap。这对我来说很有用。我没有提到需要的模板 – Dan