http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Types-property-DATE Oh hey ein Datum Datentyp ...
Wie auch immer, bevor Sie Ihre Frage zu beantworten! (Siehe die tl; dr für ein Datum Datentyp Beispiel)
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field-cfg-convert
Eine Funktion, die den Wert, der durch den Leser in ein Objekt bereitgestellt umwandelt, die in dem Modell gespeichert werden. Es wird folgende Parameter übergeben:
v: Misch
Der Datenwert, wie durch den Reader zu lesen, wenn die konfigurierte default undefined verwenden wird. Empf .: Ext.Data.Modell
Das Datenobjekt, das das Modell enthält, wie es bisher vom Reader gelesen wurde. Beachten Sie, dass das Modell zu diesem Zeitpunkt möglicherweise nicht vollständig ausgefüllt ist, da die Felder in der Reihenfolge gelesen werden, in der sie in Ihrem Felder-Array definiert sind.
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}
]
});
Ah und an dieser Stelle fand ich die Quelle Ihres Beispiels;)
// 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.
};
All dies tut, ist es, einen neuen Datentyp mehr deklarieren oder weniger. es wäre so etwas wie
// 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 aussehen; DR
Jetzt tatsächlich Ihre -original- Frage zu beantworten:
Ext DOES ein Datum Art haben Sie verwenden können: Ext.data.Types .DATE (sowie ein paar andere).
Ich nehme an Typ: Datum hat nicht funktioniert, sonst wären wir nicht hier! Also wahrscheinlich sind nur 4 richtig referenziert. Aber! dies funktioniert:
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!
Fiddle Arbeitscode:
http://www.senchafiddle.com/#w97Oe
Ich werde weiter daran arbeiten. Hoffentlich wird es in den nächsten Tagen eine Antwort für Sie geben. Bleib dran :) –