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
我会对此进一步研究。希望在接下来的几天会有一个答案。敬请期待:) –