JSON background Date Format Conversion

Source: Internet
Author: User
 

If you use the extjs framework for Web application development, you may encounter many time-related issues. The main problems may occur in two aspects:

1. After reading data in the date format in the background database, package the data in JSON format and upload it to the foreground for display.

2. The front-end is formatted (for example, yyyy-mm-dd hh: mm: ss) In JSON format.

The following describes these two important issues in detail.

When the conversion includes year, month, day, hour, minute, and second,

 

String x="[{'id':'1','fixOkdate':'2013-07-23 10:47:00','containerNumber':'1',
'evaluatePrice':33,'contractor':'','operator':'','containerType':'','containerLevel':''
,'loggingMan':'','loggingDate':'','fixGroup':'','qc':''}]";
JSONArray obj = JSONArray.fromObject(x);List<Map> list = JSONArray.toList(obj, Map.class);for (int i = 0; i < list.size(); i++) {Map temp = list.get(i);String id = temp.get("id").toString();System.out.println(id);}

X must be an array. Only strings in JSON format can get the id value correctly.

String param="{'id':'3','containerProperty':'3','boatName':'3','voyageNumber':'3',
'getContainerDate':null,'destinationPort':'3','ladingbillNumber':'3','containerType':'3',
'containerSize':'3'}";
YxFieldneedcn b=(YxFieldneedcn) MyTools.formJSONtoBean(param, YxFieldneedcn.class);System.out.println(b);

When a string in JSON format contains a time string, for example, getcontainerdate, the value is null or yyyy-mm-dd hh: mm: SS, otherwise, an error occurs during conversion to a Java object. It cannot be a null string.

Extjs learning ....

1. The function can be automatically executed and parameters can be passed to the function.

(function(name){       console.log(name);    }('wocao'))

2,

Detection type

 Ext.onReady(function(){       var i,j,k,defaults;       var xx='222'||{};       var yy=222||{};       var zz=defaults||{};       console.log(typeof xx);// string       console.log(typeof yy);//number       console.log(typeof zz);//object }); 

3. Output object and copy object

Ext. onready (function () {var I, J, K, defaults; var OBJ = {A: 'aaa', B: 'bbb ', C: 'ccc '}; vaR xx = defaults | {}; // attributes of the loop output object for (I in OBJ) {console. log (OBJ [I]); XX [I] = OBJ [I];} For (J in XX) {console. log (XX [J]) ;}});

Alternatively, you can directly use the functions provided by the Framework in extjs4.

Ext. onready (function () {var I, J, K, defaults; var OBJ = {A: 'aaa', B: 'bbb ', C: 'ccc '}; vaR xx = defaults | {}; // attributes of the loop output object for (I in OBJ) {Ext. apply (XX, OBJ);} For (J in XX) {console. log (XX [J]) ;}});

4,

var x=trueconsole.log(!x?'222':'333');

When! If the value of X is true, the output is 222. If the value of X is false, the output is 333.

5,

console.log(Ext.isObject(null));

If the value is false, the Javascript bug about null value is corrected.

6. Use Ext. iterate to iterate the object

var x={x:'1',y:'2',z:function(){}};Ext.iterate(x,function(record,value){   console.log(record);   console.log(value);},null);

7,

(function() {  var x='2222';  pp.bb={    et:function(){      console.log('et');    }  }})();console.log(pp.bb);

When () is added to a function, the function is executed immediately. In this way, you can access the attributes and methods defined in the function. When adding a method, it must be in an attribute object.

8. Obtain the parameters in the store.

var store=Ext.StoreManager.get('yx.Summary');var f=store.filters.items;console.log(f[1].value);

In this way, you cannot use store. Proxy. extraparams. Instead, you should use store. Filter ("key", "value ")

9

var obj={'x':'bb'};Ext.ClassManager.setNamespace('MyCompany.pkg.Example',obj);alert(MyCompany.pkg.Example===obj);

Returns true.

10,

Ext.define('Logger', {             singleton: true,             log: function(msg) {                 console.log(msg);             }});Logger.log('Hello');

11,

Ext.define('my',{  extend: 'Ext.panel.Panel',  bb:'bb_value',  cc:function(){     console.log('cc_function');  }});Ext.define('my',{   override:'my',   dd:'dd'});var x=new my();console.log(x.bb);

12,

In the extjs4 environment, you can perform this loop.

var xx=['dd','bb','cc'],t=xx.shift(); for ( ; t ;t = xx.shift()) {    console.log(t); }

// Shift () is used to delete the first element in the array and return

When the preceding loop determines whether T is null or undefined, JavaScript treats this value as false and stops execution.

13,

var m=new  cthd.model.xx.EvaluateBillFee({id:records[0].data.id});

In this way, you can obtain a new model instance.

14. How to save the last used variable in extjs4

Ext. onready (function () {If (ext. blank_image_url.substr )! = "Data") {Ext. blank_image_url = ". /loader/images/s.gif ";} // Add extjs code var els = ext. select (". smallimg "); var bigimg = ext. getdom ("bigimg"); var Index = 0; var fn = function (v) {console. log (INDEX); var ell = els; ell. item (index ). removecls ("select"); Index = index + V; If (index <0) {Index = 2;} else if (index> 2) {Index = 0 ;}; vaR El = ell. item (INDEX); El. radiocls ("select"); var src = el. dom. SRC; bigimg. src = SRC. substr (0, SRC. length-6) + SRC. substr (SRC. length-5) ;}; Ext. create ("Ext. util. keynav "," div1 ", {up: function () {fn (-1) ;}, down: function () {fn (1) ;}, scope: this });});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.