http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Types-property-DATE 嘿日期數據類型...
無論如何,回答你的問題之前! (參見TL;博士日期數據類型的例子)
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field-cfg-convert
它轉換由讀取器提供到將被存儲在模型中的對象的值的函數。它是通過以下參數:
ν:混合
如由讀取器讀出,如果未定義,則取配置默認值的數據值。 rec:Ext.data。模型
包含該模型的數據對象至今由Reader讀取。請注意,此時模型可能沒有完全填充,因爲字段是按照它們在字段數組中定義的順序讀取的。
Ext.define('Dude', {
extend: 'Ext.data.Model',
fields: [
{name: 'locationInCity', convert: function(rawDataValue,record){
return record.location+', '+record.city //would be something like Sprooklyn,Springfield
}},
{name: 'firstname', mapping: 'name.first'},
{name: 'lastname', mapping: 'name.last'},
{name: 'city', defaultValue: 'homeless'},
'state',
{name: 'location', convert: location}
]
});
啊,在這一點上,我發現你的榜樣的來源;)
// Add a new Field data type which stores a VELatLong object in the Record.
Ext.data.Types.VELATLONG = {
convert: function(v, data) { // convert(value,record)
return new VELatLong(data.lat, data.long); //VELatLong was declared previously in another library as something according to example
},
sortType: function(v) {
return v.Latitude; // When sorting, order by latitude //VELatLong will have lat and long properties, this is for complex sorting
},
type: 'VELatLong' //This is what we use to reference it.
};
這一切確實是聲明一個新的數據類型更多或更少。它看起來像
// Add a new Field data type which stores a VELatLong object in the Record.
Ext.data.Types.tehDate = {
convert: function(v, data) { // convert(value,record)
return new date(v);
},
sortType: function(v) {
return v; // eh i have no idea whether its going to actually just accept date comparisons, though no there's real reason why it shouldn't
},
type: 'tehDate' //This is what we use to reference it.
};
^-- some of this is untested.
TL; DR
我們真正回答您的問題-original-:
內線確實有可以使用日期類型:Ext.data.Types .DATE(以及其他幾個)。
我認爲類型:日期沒有工作,否則我們不會在這裏!所以可能只有4個被正確引用。 但是!這樣做的工作:
var types = Ext.data.Types; // allow shorthand type access
Ext.define('Unit', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'dated', type: types.DATE },
{ name: 'pie', type: 'string' },
]
}
});
abc=Ext.create('Unit',{
dated: new Date().toString(),
pie:'hello'
})
console.log(abc)
console.log(abc.get('dated').getUTCFullYear())//it liiiiives!
的工作代碼小提琴:
http://www.senchafiddle.com/#w97Oe
我會對此進一步研究。希望在接下來的幾天會有一個答案。敬請期待:) –