2013-03-30 46 views
4

我試圖在灰燼模型設置默認類型,但只有某些類型的工作:不能設置默認值在灰燼模型數和字符串類型

createdDate: DS.attr('date', {defaultValue: new Date()}) // Works 
    createdDate: DS.attr('boolean', {defaultValue: false}) // Works 
    createdDate: DS.attr('string', {defaultValue: "example"}) // Doesn't work - attribute null 
    createdDate: DS.attr('number', {defaultValue: 99}) // Doesn't work - attribute null 

我缺少什麼?

回答

1

根據here,你所有的代碼都沒問題。 但是,looks like defaultValue僅處理undefined個案(您的布爾值和日期)。 您可以嘗試處理那些帶有函數的null個案,您將傳遞第二個參數。