Sencha touch 如何在Sencha Touch 2型号中存储日期
在SenchaTouch2中,似乎只有string、int、float和boolean数据类型。那么如何存储日期时间 更新 好的,我发现我可以使用Sencha touch 如何在Sencha Touch 2型号中存储日期,sencha-touch,extjs,sencha-touch-2,Sencha Touch,Extjs,Sencha Touch 2,在SenchaTouch2中,似乎只有string、int、float和boolean数据类型。那么如何存储日期时间 更新 好的,我发现我可以使用convert()转换值: convert:函数将原始数据值从数据转换为 块插入要存储在字段中的数据。函数被传递 下列参数: -v:混合 由数据库读取的数据值 读卡器,如果未定义,将使用配置的默认值。 -记录:混合 包含读卡器读取的行的数据对象。取决于 读卡器类型,可以是数组(ArrayReader),也可以是对象 (JsonReader)或XML元素
convert()
转换值:
convert
:函数将原始数据值从数据转换为
块插入要存储在字段中的数据。函数被传递
下列参数:-v:混合
由数据库读取的数据值 读卡器,如果未定义,将使用配置的默认值。
-记录:混合
包含读卡器读取的行的数据对象。取决于 读卡器类型,可以是数组(ArrayReader),也可以是对象 (JsonReader)或XML元素
但我并不真正理解代码。对于
convert()
,什么设置参数?为什么未使用第一个参数,它的用途是什么?如何获取/设置此类自定义类型(在convert()
中它是变成v
还是data
) Sencha Touch 1.0支持
但是,Sencha Touch 2
仅支持模型的数据类型
- 串
- 整数
- 浮动
- 布尔值
日期
放在字符串
格式中,然后把它转换成
date
使用API的对象
哦,嘿,日期数据类型
无论如何,在回答你的问题之前!太长了,读不下去了(见日期数据类型的例子)
将读取器提供的值转换为将存储在模型中的对象的函数。将传递以下参数:
v:混合
读卡器读取的数据值(如果未定义)将使用配置的defaultValue。
rec:Ext.data.Model
到目前为止读取器读取的包含模型的数据对象。请注意,此时可能无法完全填充模型,因为字段是按照字段数组中定义的顺序读取的。
啊,在这一点上,我找到了你例子的来源;)所有这些都或多或少地声明了一个新的数据类型。看起来像
// 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;博士
现在来实际回答你的原始问题:
Ext确实有一个可以使用的日期类型:Ext.data.Types.date(以及其他一些类型)
我假设类型:日期不起作用,否则我们就不会在这里了!因此,可能只有4个被正确引用。
但是这确实有效:
工作代码的混乱:
仅以简单的方式概括上述内容: 是的,您可以轻松地将日期存储为模型中的日期。为此,您需要:
required
字段中包含fileExt.data.Types
):
{date:date("d.m.Y")}
Ext.Date.format(form.getValues().date, 'd.m.Y').
就这样!现在您拥有了原生日期字段的所有功能,即您可以轻松地进行分组、排序等操作 所以我在Sencha外面做这些?这意味着我不能使用Sencha/Ext的模型验证等?我使用Sencha模型的验证和单独进行日期验证似乎有点奇怪?别无选择,除非你想回到ST1Jiew Meng是正确的。实际上,有一个更好的选择是创建带有验证的自定义数据类型。使用字符串可能会起作用,但不会编程,因为验证完全超出模型定义。我将在这方面进一步努力。希望在接下来的几天里会有你的答案。请继续关注:)这个答案是错误的。Sencha Touch 2绝对有“日期”类型。看一看,我将在这方面做进一步的工作。希望在接下来的几天里会有你的答案。请继续关注:)我想我写这篇文章的时候受到了糖热的影响/
// 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.
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!
{name: 'date', type: Ext.data.Types.DATE, dateFormat: 'd.m.Y'};
{date:date("d.m.Y")}
Ext.Date.format(form.getValues().date, 'd.m.Y').