2013년 10월 16일 수요일

Formatting dates within an Ext.XTemplate

1. First, we will create a simple Ext.XTemplate and render it to the document's body,
applying a simple data object, containing a date:
var data = {
date: '5/8/1986 12:30:00'
};
var tpl = new Ext.XTemplate('{date}');
tpl.overwrite(Ext.getBody(), data); // outputs '5/8/1986 12:30:00'

2. We then use the date function, passing it a formatting string to format the
date property:
var tpl = new Ext.XTemplate('{date:date("Y-m-d")}');
tpl.overwrite(Ext.getBody(), data); // outputs '1986-08-05'

3. We can also use the globally defined patterns that we used in Chapter 2,
Manipulating the Dom, Handling Events, and Making AJAX Requests, by
concatenating them into the XTemplate's HTML string.
var tpl = new Ext.XTemplate('{date:date("' + Ext.Date.patterns.
LongDate + '")} ');
tpl.overwrite(Ext.getBody(), data); // outputs 'Tuesday, August
05, 1986'

댓글 없음:

댓글 쓰기