http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Types-property-DATE
哦,日期数据类型...
无论如何,在回答你的问题之前!(有关日期数据类型示例,请参见 tl;dr)
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field-cfg-convert
将 Reader 提供的值转换为将存储在模型中的对象的函数。它传递了以下参数:
v : 混合
Reader 读取的数据值,如果未定义将使用配置的 defaultValue。记录:Ext.data.Model
到目前为止,阅读器读取的包含模型的数据对象。请注意,此时模型可能未完全填充,因为字段是按照它们在字段数组中定义的顺序读取的。
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;博士
现在要实际回答您的 -original- 问题:
Ext 有一个可以使用的日期类型:Ext.data.Types.DATE(以及其他一些)。
我假设 type: 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