在做项目中,看到用ext做的时间控件,只显示年月。
js代码:
var combSpField=[{
name:"id",
mapping:"id"
},{
name:"value",
mapping:"value"
}];
var combStore=new Ext.data.JsonStore({
url:basePath + "/tenceKip.sdo",
baseParams :{
cmd:" "
},
root:"date",
fields : combSpField
});
combStore.load();
opTimeListComb = new Ext.form.ComboBox({
store : combStore,
displayField : "value",
valueField : "id",
typeAhead : true,
editable : false,
mode : "local",
width : 90,
triggerAction : "all",
selectOnFocus : true,
renderTo : "selectMonth",
listeners : {
"render" : function() {
combStore.load({
callback : function() {
if (combStore.getTotalCount() > 0) {
opTimeListComb
.setValue(combStore
.getAt(0).data.id);
}
}
});
}
}
});
var monthBox = new Ext.Panel({
width : 171,
autoHeight : true,
border : false,
items : [{
contentEl : "monthBox",
border : false
}]
});
var monthWin = new Ext.Window({
width : 190,
autoHeight : true,
plain : true,
modal : true,
closeAction : "hide",
items : [monthBox]
});
Ext.get("opTimeA").on("click", function(e, t) {
monthWin.show();
monthWin.show().alignTo(t, "tl-bl?");
});
Ext.fly("monthCommit").on("click", function(e, t) {
//需要执行的代码
});
在页面中需要加入以下代码:
<div id="monthBox" class="x-hide-display">
<div id="selectMonth" style="float: left;"></div>
<div>
<button id="monthCommit" type="submit" style="margin-left: 80px;float:left;">
确定
</button>
</div>
<div style="clear: both"></div>
</div>
由于ext只有显示年月日的代码,这样就可以只保证显示年月的。