EXTJS日期字段问题,请帮忙

如何解决EXTJS日期字段问题,请帮忙

| 我在尝试弄清楚这是怎么回事时遇到了麻烦。我从回调中使用Extjs和AJAX与JsonStore一起使用,我在ASP中的页面调用数据库并返回此字段中的某些字段,其中存在一个Date,并且此日期返回正确的日期,例如:\“ date_creat_post \”:\“ 29 \\ u002F04 \\ u002F2011 \“ ... 现在,一旦我在datagrid的页面中查看了我的输出,就会得到以下信息: 04/05/2013 <---->它在回调中返回的日期是04/05/2011 06/05/2012 <---->它在回调中返回的日期是06/05/2010 2012年7月4日<---->它在回调中返回的日期是07/04/2010 我看了所有的代码,看看它们是否是我要向日期添加1年的地方。 但找不到。我已经尝试了至少2天,以解决此问题。 这是我的代码:
    Ext.onReady(function(){

Ext.QuickTips.init();

// for this demo configure local and remote urls for demo purposes
var url = {
    local:  \'\',// static data file
    remote: \'../myurl.asp\'
};

// configure whether filter query is encoded or not (initially)
var encode = true;

// configure whether filtering is performed locally or remotely (initially)
var local = false;

var PostStore = new Ext.data.JsonStore({
    // store configs
    autoDestroy: true,baseParams : {filter : \'[{\"type\":\"boolean\",\"value\":false,\"field\":\"is_sent_post\"}]\'},// we start only with is_sent == false
    url:  url.remote,remoteSort: false,sortInfo: {
        field: \'date_creat_post\',direction: \'DESC\'
    },storeId: \'Post_Store\',// reader configs
    idProperty: \'id_post\',root: \'Post\',totalProperty: \'totalcount\',fields: [{
        name: \'id_post\',type: \'number\'
    },{
        name: \'name_post\',type: \'string\'
    },{
        name: \'date_creat_post\',type: \'date\'//,//dateFormat: \'Y-m-d H:i:s\'
    },{
        name: \'from_addr_post\',{
        name: \'sender_name_post\',{
        name: \'is_sent_post\',type: \'boolean\'
    },{
        name: \'date_sending_post\',{
        name: \'html_post\',{
        name: \'list_send_post\',type: \'number\'
    }],writer: new Ext.data.JsonWriter({
                                writeAllFields: true    
                                    }),autoSave: false,batch: true
});

var filters = new Ext.ux.grid.GridFilters({
    // encode and local configuration options defined previously for easier reuse
    encode: encode,// json encode the filter query
    local: local,// defaults to false (remote filtering)
    filters: [{
        type: \'numeric\',dataIndex: \'id_post\'
    },{
        type: \'string\',dataIndex: \'name_post\'
    },{
        type: \'date\',dataIndex: \'date_creat_post\'
    },dataIndex: \'from_addr_post\'
    },dataIndex: \'sender_name_post\'
    },{
        type: \'boolean\',dataIndex: \'is_sent_post\'
    },dataIndex: \'date_sending_post\'
    },dataIndex: \'html_post\'
    },{
        type: \'numeric\',dataIndex: \'list_send_post\'
    }]
});    

// use a factory method to reduce code while demonstrating
// that the GridFilter plugin may be configured with or without
// the filter types (the filters may be specified on the column model
var createColModel = function (finish,start) {

    var columns = [{
        dataIndex: \'id_post\',hidden:true,header: \'Id\',// instead of specifying filter config just specify filterable=true
        // to use store\'s field\'s type property (if type property not
        // explicitly specified in store config it will be \'auto\' which
        // GridFilters will assume to be \'StringFilter\'
        filterable: true
        //,filter: {type: \'numeric\'}
    },{
        dataIndex: \'name_post\',header: \'Subject\',width: 150,id: \'postname\',filter: {
            type: \'string\'
            // specify disabled to disable the filter menu
            //,disabled: true
        }
    },{
        dataIndex: \'date_creat_post\',header: \'Date Created\',renderer:  Ext.util.Format.dateRenderer(\'d/m/Y\'),filter: {
            type: \'date\'     // specify type here or in store fields config
        }            
    },{
        dataIndex: \'from_addr_post\',header: \'From Address\',id: \'fromaddress\',{
        dataIndex: \'sender_name_post\',header: \'Sender Name\',id: \'sendername\',{
        dataIndex: \'is_sent_post\',header: \'Status\',filter: {
            type: \'boolean\'  // specify type here or in store fields config
        },renderer: function(value) {
            var rtn = (value == 1) ? \'sent\' : \'stand-by\';
            return rtn
        }
    },{
        dataIndex: \'date_sending_post\',header: \'Sending Date\',//renderer: Ext.util.Format.dateRenderer(\'d/m/Y\'),{
        dataIndex: \'list_send_post\',header: \'Opticians list\',id: \'optlist\',filter: {
            type: \'number\'
            // specify disabled to disable the filter menu
            //,disabled: true
        }
    }];

    return new Ext.grid.ColumnModel({
        columns: columns.slice(start || 0,finish),defaults: {
            sortable: true
        }
    });
};
/*
//======================contextMenu triggered by right click========================================
*/

var doRowCtxMenu = function ( thisGrid,rowIndex,cellIndex,evtObj )
{
    //Ext.popup.msg(\'Done !\',\'Right clicked !\');   
    evtObj.stopEvent();
    var sm = thisGrid.getSelectionModel();
    var records = sm.getSelections(); // returns an array of Ext.data.Records

    try
    {
        //var r = records[0]; // get the 1st Ext.data.Record of the list
        thisGrid.rowCtxMenu = new Ext.menu.Menu({
            items: [{
            text    : \'<span style=\"color:red;\">Delete Selected Email ?</span>\',handler : function ()   {
                                    deletePost(records,thisGrid);
                                    }
                    }]
        });
        thisGrid.rowCtxMenu.showAt(evtObj.getXY());
    }
    catch(err)
    {
        Ext.popup.msg(\'Warning !\',\'You need to select a row first !\'); 
    }
};
/*
//======================END contextMenu triggered by right click========================================
//======================Delete Post Fonction =================================================
*/
function deletePost(records,thisGrid)
{

    Ext.Msg.show({
        title   :\'Warning !\',msg     : \'You are about to delete 1 email !\',buttons : Ext.Msg.YESNOCANCEL,fn      : function(btn){
                    if (btn==\'yes\')
                    { 
                        var store = thisGrid.getStore();
                        var s = thisGrid.getSelectionModel().getSelections();
                        for(var i = 0,r; r = s[i]; i++){
                            store.remove(r);
                        }
                        store.proxy.conn.url = \'../myurl.asp\';
                        store.save();
                        lastOptions = store.lastOptions;
                        /*Ext.apply(lastOptions.params,{
                        //myNewParam: true
                        });*/
                        store.load(lastOptions);
                    }
    },animEl  : \'elId\'
    }); 
}
 /*
//======================End delete Function========================================
*/
var Postgrid = new Ext.grid.GridPanel({
    id:\'post_grid\',border: false,width: 462,height:250,store: PostStore,colModel: createColModel(8),loadMask: true,viewConfig:{
    emptyText:\'No Post to display,change/clear your filters,refresh the grid or add a new Email!\'
    },plugins: [filters],sm: new Ext.grid.RowSelectionModel({
                 singleSelect: true,listeners: {
                 rowselect: function(sm,row,rec) {
                                    Ext.getCmp(\"post_form\").getForm().loadRecord(rec);
                                    //Ext.getCmp(\"htmlEdit\").setValue(\"sdcdsdcdscsdc\");
                                                    }
                             }
    }),//autoExpandColumn: \'company\',listeners: {
        cellcontextmenu : doRowCtxMenu,render: {
            fn: function(){
                PostStore.load({
                    params: {
                        start: 0,limit: 50
                    }
                });
            }
        }
    },bbar: new Ext.PagingToolbar({
        store: PostStore,pageSize: 50,plugins: [filters]
    })
});

// add some buttons to bottom toolbar just for demonstration purposes
Postgrid.getBottomToolbar().add([
    \'->\',{
        text: \'Clear Filter Data\',handler: function () {
            Postgrid.filters.clearFilters();
        } 
    }   
]);
var panelGrid = new Ext.Panel({
            width : 462,height : 250,layout : \'fit\',renderTo: \'post-grid\',items: Postgrid
                        });

   });
我将在firebug json中提供回调:
    {\"totalcount\":3,\"Post\": [{\"id_post\": 83,\"name_post\": \"ghfgh\",\"date_creat_post\": \"29\\u002F04\\u002F2011\",\"from_addr_post\": \"fgh@sdf.com\",\"sender_name_post\": \"gfh\",\"is_sent_post\": false,\"date_sending_post\": \"29\\u002F04\\u002F2011\",\"html_post\": \"<p>dfgdgdgd<\\u002Fp>\",\"list_send_post\": null},{\"id_post\": 61,\"name_post\": \"thomas test\",\"date_creat_post\": \"28\\u002F07\\u002F2010\",\"from_addr_post\": \"\",\"sender_name_post\": \"\",\"date_sending_post\": \"28\\u002F07\\u002F2010\",\"html_post\": \"<p>test test test ets<\\u002Fp>\",{\"id_post\": 59,\"name_post\": \"kevin test\",\"date_creat_post\": \"29\\u002F06\\u002F2010\",\"from_addr_post\": \"kevin@art-systems.net\",\"sender_name_post\": \"kevin@art-systems.net\",\"date_sending_post\": \"29\\u002F06\\u002F2010\",\"html_post\": \"<p>jkljljoi ioijiio ijiojio oijio joijoi<\\u002Fp>\\u000A<p>&nbsp;<\\u002Fp>\\u000A<p><span style=\\u0022background-color: #ffffff;\\u0022>igiuihhuhi<\\u002Fspan><\\u002Fp>\",\"list_send_post\": null}]}
在此先感谢,我希望邪恶的网络上的某些人能对我有所帮助。 干杯。 所以在尝试了许多解决方案后我就来解决这个问题 经过多次尝试格式化并插入我的msSQL数据库中的日期示例 这个问题就是问题:13 \\ 09 \\ 2011(d / m / Y)变成了这个09/01/2012(d / m / Y),所以由于某种原因将月份13添加到了月份,所以说13个月不存在,因此日期将为2012年9月1日。 再次查看之后,它的格式似乎还没确定,所以我将其更改为de(m / d / Y),而当我在(extjs)中的datefield上击中13天时,我立即收到了SQL错误。 \“将varchar数据类型转换为日期时间数据类型导致超出范围的值。” 并不断有人现在有任何想法吗???     

解决方法

您可以尝试创建自己的一个解析日期的方法,而不是使用内置的that2 Date。
ataIndex: \'date_creat_post\',header: \'Date Created\',renderer:  daterenderer
然后是您的
daterenderer
的函数:
function dateRenderer(value,id,r) {
 var myDate = r.data[\'date_creat_post\'];
 // do some things here to strip out the date and make it into a happy format
 var d = new Date(myDate);
 return d.format(\'d/m/Y\');
}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-