EXTJS4.0.7开发积累(10)

来源:互联网 发布:java package类 编辑:程序博客网 时间:2024/04/29 10:38

EXTJS4.0.7开发积累
有从网络上搜索到的资源,也有自己开发中的总结,侵权告知删除!
json={"companytown":"xiamen"}

var companytown =JSON.parse(json);

console.log("kkkk:"+companytown.companytown);字符串和数组间的相互转换

var where_value_array =this.record.get('where_value').split(",");//字符串到数组

var valueArray=new Array();

valueArray.toString();//数组到字符串Radiogroup的change事件处理(在4.0.7中会触发两次:checked-unchecked,unchecked-checked)

,listeners:{
change:function(field, newValue,oldValue){
//console.info('type:'+this.up('#where_up_radio_panel').up('panel').record.get('hive_type_name'));
//console.info('newValue:'+value.oper);
// console.info('newValue:'+);
if(!Ext.isArray(newValue['oper'])) {
}
}
}
 
//oper是radiogrou的name值

控件拷贝(每个render出来的控件都有ID,直接拷贝这个控件,会有ID的重问题,导致不必要的问题)方法upperestpanel.down('#up_value_panel').add(remainItem.cloneConfig());

在store加载的时候便完成grid的select

(已经编写了grid的store加载事件和grid的行选择事件,希望在加载完后立刻就触发第一行的select事件,如下):

在store的load方法中添加一个回调函数。

'afterrender':function(){
var me = this;
this.getStore().load(
{
params:{
start: 0,
limit: 20
},
callback:function(){
console.info('store.count:'+me.getStore().count(false));
if(me.getStore().count(false)>0)
me.getSelectionModel().select(0);
}
}
);
},Up/down查找带有itemId的控件This.up('#itemId')
This.down('#itemId')控件创建时赋值方法(为控件添加额外的值)

方法一:【控件创建完成后才添加额外的值,额外值不作控件显示使用】

var view =Ext.widget('whereGridInput');

Ext.apply(view, {

           hive_tbl_col_comment:grid.getStore().getAt(rowIndex).get('hive_tbl_col_comment'),

            editRowIndex:rowIndex

        });

方法二:【在控件创建时就添加额外的值,适合初始化时设置控件的显示用】

Ext.create('widget.whereGridInput',{

           hive_tbl_col_comment:grid.getStore().getAt(rowIndex).get('hive_tbl_col_comment'),

            editRowIndex:rowIndex});actioncolumn里面获取row值

where_grid_input_fn:function(grid,rowIndex, colIndex,e){

console.info('hive_tbl_col_comment:'+grid.getStore().getAt(rowIndex).get('hive_tbl_col_comment'));

}Dynamicallyadd cellediting plugin AFTER grid has been created.

App.GridPanel1.initPlugin(

    Ext.create('Ext.grid.plugin.CellEditing', {

        clicksToEdit: 1

    });

);多个actioncolumn图标动作的控制定义里面fire出不同的事件标志:
handler: function(grid, rowIndex, colIndex,e) {
this.fireEvent('additemclick',grid,rowIndex,colIndex,e);
}
handler: function(grid, rowIndex, colIndex,e) {
this.fireEvent('addcomplexitemclick',grid,rowIndex,colIndex,e);
}
handler: function(grid, rowIndex, colIndex,e) {
this.fireEvent('deleteitemclick',grid,rowIndex,colIndex,e);
}
在controller里面统一捕捉:
,'queryBoard actioncolumn':{
deleteitemclick:this.select_grid_delete_fn,
additemclick:this.select_grid_add_fn,
addcomplexitemclick:this.select_grid_add_complex_fn
}grid actionColumn图标间距控制

.x-action-col-icon {

            height: 16px;

            width: 16px;

            margin-right: 8px;

        }

extjs-4.1.1如何把store提交到后台

前台部分 首先定义一个数组,用来储存STORE里的值。之后利用store自带的each遍历方法把数组填满。最后建一个ajax请求传送到后台即可。
var lstAddRecord=new Array(); store.each(function(record) {       
lstAddRecord.push(record.data); });
Ext.Ajax.request({     
url: 'function/rivaldata/rivalDataAction.do?tag=add',    
params: {strJson:Ext.encode(lstAddRecord)} 
});  
后台解析部分 主要是利用了JSON-Lib包,实现了关键功能。  
String strJson=request.getParameter("strJson");
JSONArray js=JSONArray.fromObject(strJson);
JSONObject jo=null;
Iterator it=js.iterator();
while(it.hasNext()){
   jo=(JSONObject)it.next();
   //follow codes are get the value :)
   String goodId=jo.getString("goodId");
   Double goodsPrice=jo.getDouble("goodsPrice");
   //ok, to do something use the vaules:)
   System.out.println("the goodId is :"+goodId);
}date计算

例如:如果添加5天,则add(Date.DAY,t);

添加2个月,add(Date.MONTH,2);

添加1年,add(Date.YEAR,1);

获取json里面root外的值

for(var key in json){
    console.log(json[key]);
}
this.getStore().load(
{
params:{
start:0,
limit: 20
},
callback: function(records, operation, success) {
var logRange=0-this.getProxy().getReader().rawData['logRange'];
var logKeepDays=0-this.getProxy().getReader().rawData['logKeepDays'];
Ext.getCmp('event_beginDate').setValue(  Ext.Date.add (new Date(),Ext.Date.DAY,logRange) );
Ext.getCmp('event_beginDate').setMinValue(  Ext.Date.add (new Date(),Ext.Date.DAY,logKeepDays) );
Ext.getCmp('event_endDate').setMinValue(  Ext.Date.add (new Date(),Ext.Date.DAY,logKeepDays) );
console.info('logRange:'+logRange);
console.info('logKeepDays:'+logKeepDays);
}
}
);

store.load()回调函数

Ext.getStore('CommonSettingsStore').load({
scope   : this,
callback: function(records, operation, success) {}
})

date计算/赋值

(Extjs4)

Ext.Date.add (new Date(),Ext.Date.DAY,1)
 
Speaking ExtJS language, you can use Ext.Date library for manipulation dates. For example:
        Ext.Date.add (new Date(),Ext.Date.DAY,1)
Depending on your code logic, you can modify the default value of date field by several ways:
 
1) In the item's value configuration:
        {
            ...
            vtype: 'daterange',
            value : Ext.Date.add (new Date(),Ext.Date.DAY,1),
            fromDateField: 'fromdate',
            ...
        }
2) During the component's event. Basically, ExtJS containers have initComponent method which is the most first running, but be sure to set your code after callParent() method in order to access items collection. Example:
 
initComponent: function() {
            ...
    this.callParent(arguments);
            this.items.getByKey('fromdate').value = Ext.Date.add (new Date(),Ext.Date.DAY,1);
            ...
}
 
var date = new Date();date.setDate(date.getDate()-1);

获取当前时间

console.info('newDate(H:i):'+Ext.Date.format(new Date(),'H:i'));

console.info('newDate('Y-m-d H:i:s'):'+Ext.Date.format(new Date(),'Y-m-d H:i:s'));

通过ID获取组件

Ext.getCmp('event_endDate').setMinValue(  Ext.Date.add (newDate(),Ext.Date.DAY,logKeepDays) );

为store设置而外参数

this.getStore().on('beforeload', function (store, options) {
var new_params = {
FromHost:hostName
,HostId:hostId
,event_beginTime:'00:00'
,event_endTime:Ext.Date.format(new Date(),'H:i')
};
Ext.apply(me.getStore().proxy.extraParams, new_params);
// alert('beforeload');
});

Java 日期计算

Date date = new Date();
System.out.println((new SimpleDateFormat("yyyy-MM-dd")).format(date));
Calendar cal = Calendar.getInstance();
//cal.setTime(date);
cal.add(Calendar.DATE, -1);
String dd=(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime())+" 00:00";
System.out.println(dd);

0 0