extjs入门小记()
想要在grid里实现精确查询,一直找不到方法,和朋友交流中得知可以用覆盖url的方式重新load store,遇到了以下问题:
Store里面的fields属性
fields : ["stuID","stuName", "stuAge", "stuHeight", "stuWeight", "schName"]
1.GET方式传到后台的值自动添加逗号
Cotroller里面点击查询按钮重新load grid:
search : function(button) {
var stuID = Ext.getCmp("accur").getValue(); //取得输入框里的值
var grid = button.up('grid');
if(stuID != null) {
grid.store.load({
url:contextPath + "stu/accurate?stuID=" + stuID
});
}
}
这是因为load的时候会把没有值的其他属性也一并传到后台,而多个参数之间会自动加逗号隔开
2.POST方式
accurSearch : function(button) {
var stuID = Ext.getCmp("accur").getValue();
var grid = button.up('grid');
if(stuID != ""&&stuID != null) {
//debugger
Ext.Ajax.request({
//url : contextPath + "stu/accurate?stuID=" + stuID, //GET方式传递参数
url: contextPath + "stu/accurate",,
params:{stID:stuID}, //必须是JSON格式
success : function(response, options) {
grid.store.removeAll();
var rrt = response.responseText;
var stu = Ext.JSON.decode(rrt);
grid.store.add(stu)
}
});
}else {
grid.getStore().currentPage = 1;
grid.getStore().load();
}
}