【问题标题】:How can I access a date typed field from an ExtJS JSonStore?如何从 ExtJS JSonStore 访问日期类型字段?
【发布时间】:2012-11-18 11:56:41
【问题描述】:

我一直在尝试使用以下代码从数据库中检索日期值和整数值:

var l_alsChampsMois, l_stoDonneesMois;

    try {
        l_alsChampsMois = [
          {name: "date_mois", type: "date", dateFormat: "Y-m-d"},
          {name: "indice", type: "integer"}
        ];

        l_stoDonneesMois = new Ext.data.JsonStore({
            fields: l_alsChampsMois,
            autoLoad: false,
            proxy: {
                type: "ajax",
                url: "/commun/req_sql/req_ind_per_mois.php",
                reader: {
                    type: "json",
                    root: "rows"
                },
                // some configs to use jsFiddle echo service (you will remove them)
                actionMethods: {
                    read: "POST"
                },
               extraParams: {
                    key:"test"
                }
            },
            listeners: {
                load: function(objStore, alsLignes, blnOk, objOptions) {
window.alert("Mois fin : " + objStore.getAt(0).get("date_mois"));
                }
            }
        });

    l_stoDonneesMois.load({params:            {
                                p_idsoc:    l_strIdSociete,
                                p_mois:        l_datDebut.getMonth() + 1,   
                                // getMonth renvoie 0 pour janvier, etc. 
                                p_annee:    l_datDebut.getFullYear(),
                                p_debut:    1,
                                p_etape:    1
                                } 
                            });

其中 l_strIdSociete 和 l_datDebut 是先前分配的变量,而 /commun/req_sql/req_ind_per_mois.php 是检索数据并将其转换为 JSON 的 PHP 页面。

它似乎工作正常(实际上,Firebug 告诉我负载确实检索了包含我期望它们的值的“date_mois”和“indice”的数据结构),只有 window.alert 返回未定义。如果我用“indice”替换“date_mois”,它会返回“indice”的预期值。

我尝试使用 objStore.getAt(0).getData()["date_mois"],但无济于事。

我对此的唯一线索是 Firebug 显示的数据结构中的“date_mois”是一个对象,但即便如此,它也不应该是未定义的,现在应该吗?我查了http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Field-cfg-type,这并没有直接给出答案。

那我做错了什么?

【问题讨论】:

  • 你能转储 objStore.getAt(0) 吗?然后查看 raw 字段以确保您确实获得了所需的数据。
  • 有趣的问题。昨天 Firebug 由于某种原因无法调试,所以我不得不处理多个 window.alert() 消息(但我没有想到 raw 字段)。够啰嗦了,raw 字段有: Object { date_mois = { date="2012-11-30 00:00:00", timezone_type=3, timezone="UTC" } , indice = "23 " } 所以看来需要的数据就在那里。
  • 也许我错了,但您认为 ext js 可以将您的日期识别为 3 个字段的对象?我以前从未见过这个。将时间作为 unix 时间戳发送,无论如何它都可以工作。
  • @Prodigy:这就是重点:我很惊讶它不能给我 JSON 返回的对象(并且 raw 字段包含)。你能给我一个从 PHP 源发送时间作为 Unix 时间戳的例子吗?
  • @Vyacheslav Voronchuk:Firebug 给出的 JSON 值与 raw 字段相同。你需要更多的信息?如果有,是什么?

标签: date types extjs4 field jsonstore


【解决方案1】:

如果需要当前时间可以使用php的time函数(注意:返回秒,JS使用毫秒),另外一种情况需要通过mktime函数转换.

【讨论】:

  • 好的,谢谢。这不是重点,但它可能会在某个时候派上用场。
猜你喜欢
  • 2011-10-17
  • 1970-01-01
  • 2013-09-24
  • 1970-01-01
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多