extjs4 combobox学习之可以用来查询的combo

来源:互联网 发布:逆袭 网络剧 在线1 编辑:程序博客网 时间:2024/05/16 03:50
/**
 * 编码选择框
 * 
 * 
 * 用法
 * 
 * xtype:'projecteditfield'
 */
Ext.define('base.view.field.ProjectEditfield', {
extend : 'Ext.form.field.ComboBox',
alias : 'widget.projecteditfield',
requires : ['base.store.PmProjectStore',
'base.model.PmProjectModel'],
displayField : 'name',
valueField : 'id',
queryMode : 'remote',// 载入其根据根据用户的交互动态的数据集。
queryParam : 'proname',// 指定向后台传参数的变量名称。Extjs4默认为query;
typeAhead : false,// 有的地方说的延时查询,事实自动选择
typeAheadDelay : 500,// 间隔时间
autoSelect : true,
minChars : 1,// 最小查询字符数量
triggerAction : 'all',
initComponent : function() {
this.store = Ext.create("base.store.PmProjectStore", {
autoLoad : false,
proxy : {
type : 'ajax',
startParam : 'page.start',
pageParam : 'page.currentPage',
limitParam : 'page.limit',
api : {
read : './pa/project!searchproname.html'
},
reader : {
type : 'json',
root : 'projects',
successProperty : 'success'
}
}
});
this.callParent(arguments);
},
listeners : {
beforequery : function(q, o) {
// 下拉时,查询数据未能获得列表中数据,手工设置下
// console.log("iscall1");
// console.log(q);
if (Ext.isEmpty(q.query)) {
q.query = q.combo.getValue();
}
}
}

});


以上代码在用的时候,最好在保存之前加上

var depname = Ext.getCmp("customerUuid").value;//取得当前保存到后台的值
var depstore = Ext.getCmp("customerUuid").store;//取得这个组件的store
var deprawvalue = Ext.getCmp('customerUuid').rawValue;//取得这个组件在渲染后显示的值
console.log(depname);
console.log(deprawvalue);
//循环查询store,找到和rawvalue值相等的项,并把id赋值给变量,为什么再赋值,因为用户有可能在combobox下拉列表框中选择后,再按回车键,

//这样会使这个组件的value变为空值,保存无效的值。所以我在保存之进行了比较再赋值,以判断是否可以保存。
for (var i= 0;i<depstore.getCount();i++){
if (depstore.getAt(i).get('fullName') == deprawvalue){
depname = depstore.getAt(i).get('id');
Ext.getCmp("customerUuid").value = depstore.getAt(i).get('id');
}
console.log(Ext.getCmp("customerUuid").value);
}



原创粉丝点击