2017-03-05 85 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