jquery extend 多个扩展方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery extend 多个扩展方法相关的知识,希望对你有一定的参考价值。

$.fn.extend({
SetDict: function (option) {
var txtControl = $(this);
if (!txtControl.hasClass("combo-text")) {
// var width = txtControl.width();
//txtControl.addClass("combo");

}
txtControl.click(function () {
var obj = option.valueControl;
var dicType = option.dicType;
var isShow = txtControl.attr("isShow");
if (isShow == null || isShow == "") {
txtControl.attr("isShow", "1");
txtControl.combogrid({
panelWidth: 250,
idField: Code,
textField: Name,
url: /Common/EntityJsonList.ashx?_method=dict&dictType= + dicType + "&tmp=" + Math.random() + &queryTextFild=Name,
method: get,
delay: 1000,
columns: [[
{ field: Name, title: 名称, width: 100 },
{ field: Code, title: 编码, width: 100 }
]],
striped: true,
editable: true,
collapsible: false, //是否可折叠的 
fit: true,
onLoadSuccess: function () {
window.setTimeout(function () {
$(".combo-arrow", option.valueControl.parent()).click();
}, 100);
},
onClickRow: function (index, row) {
txtControl.val(row.Name);
option.valueControl.val(row.Code);
}, //自动大小
keyHandler: {
up: function () { //【向上键】押下处理
//取得选中行
var selected = txtControl.combogrid(grid).datagrid(getSelected);
if (selected) {
//取得选中行的rowIndex
var index = txtControl.combogrid(grid).datagrid(getRowIndex, selected);
txtControl.val(selected.Name);
option.valueControl.val(selected.Code);
//向上移动到第一行为止
if (index > 0) {
txtControl.combogrid(grid).datagrid(selectRow, index - 1);
}
} else {
var rows = txtControl.combogrid(grid).datagrid(getRows);
txtControl.combogrid(grid).datagrid(selectRow, rows.length - 1);

}
},
down: function () { //【向下键】押下处理
//取得选中行
var selected = txtControl.combogrid(grid).datagrid(getSelected);
if (selected) {
txtControl.val(selected.Name);
option.valueControl.val(selected.Code);
//取得选中行的rowIndex
var index = txtControl.combogrid(grid).datagrid(getRowIndex, selected);
//向下移动到当页最后一行为止
if (index < txtControl.combogrid(grid).datagrid(getData).rows.length - 1) {
txtControl.combogrid(grid).datagrid(selectRow, index + 1);
}
} else {
txtControl.combogrid(grid).datagrid(selectRow, 0);
}
},
enter: function () { //【回车键】押下处理
txtControl.combogrid(hidePanel);
var selected = txtControl.combogrid(grid).datagrid(getSelected);
if (selected) {
txtControl.val(selected.Name);
option.valueControl.val(selected.Code);
}

},
query: function (keyword) { //【动态搜索】处理
//设置查询参数
var queryParams = txtControl.combogrid("grid").datagrid(options).queryParams;
queryParams.keyword = keyword;
txtControl.combogrid("grid").datagrid(options).queryParams = queryParams;
//重新加载
txtControl.combogrid("grid").datagrid("reload");
txtControl.combogrid("setValue", keyword);
}
},
mode: remote,
fitColumns: true
});
}
});
}
});
$.fn.extend({
SetCombo: function (option) {/// <reference path="../Common/JGridJson.cs" />
var entityType = option.entityType;
var textField = option.textField;
var textControl = $(this);
var panelWidth = option.panelWidth;
var idFild = option.idFild;
var valueControl = option.valueControl;
var panelHeight = option.panelHeight;
var columns = option.columns;
var where = option.where;
//var keyword = option.keyword;
var pageSize = option.pageSize;
if (option.pageSize == null) {
pageSize = 10;
}
var obj = valueControl;
if (panelHeight == null) {
panelHeight = 300;
}
var url = /common/EntityJsonList.ashx?entityType= + option.entityType + &_method=entity&tmp= + Math.random() + &queryTextFild= + textField;
if (where) {
url += "&where=" + where;
}
if (panelWidth == null) {
panelWidth = 500;
}
if (valueControl.val() != "") {
url += "&defaultValue=" + escape(valueControl.val());
}
var id = Id;
if (idFild != null) {
id = idFild;
}
url += "&idFild=" + id;
textControl.click(function () {
var a = textControl.attr("isShow");
if (a == "" || a == null) {
textControl.attr("isShow", "1");
textControl.combogrid({
panelWidth: panelWidth,
panelHeight: panelHeight,
idField: id,
textField: textField,
url: url,
method: get,
delay: 1000,
pagination: true, //是否分页 
rownumbers: true, //序号
pageSize: pageSize, //每页显示的记录条数,默认为10 
pageList: [pageSize, 10, 20, 30, 40, 50, 100, 200], //可以设置每页记录条数的列表 
columns: columns,
striped: true,
editable: true,
collapsible: false, //是否可折叠的 
fit: true,
onLoadSuccess: function () {
window.setTimeout(function () {
$(".combo-arrow", option.valueControl.parent()).click();
}, 100);
},
onClickRow: function (index, row) {
valueControl.val(UTIL.getJsonByKey(row, idFild));
textControl.val(UTIL.getJsonByKey(row, textField));
}, //
keyHandler: {
up: function () { //【向上键】押下处理
//取得选中行
var selected = textControl.combogrid(grid).datagrid(getSelected);
if (selected) {
//取得选中行的rowIndex = txtControlex
var index = combogrid(grid).datagrid(getRowIndex, selected);
valueControl.val(UTIL.getJsonByKey(selected, idFild));
textControl.val(UTIL.getJsonByKey(selected, textField));
//向上移动到第一行为止
if (index > 0) {
textControl.combogrid(grid).datagrid(selectRow, index - 1);
}
} else {
var rows = textControl.combogrid(grid).datagrid(getRows);
textControl.combogrid(grid).datagrid(selectRow, rows.length - 1);
}
},
down: function () { //【向下键】押下处理
//取得选中行
var selected = textControl.combogrid(grid).datagrid(getSelected);
if (selected) {
valueControl.val(UTIL.getJsonByKey(selected, idFild));
textControl.val(UTIL.getJsonByKey(selected, textField));
//取得选中行的rowIndex
var index = textControl.combogrid(grid).datagrid(getRowIndex, selected);
//向下移动到当页最后一行为止
if (index < textControl.combogrid(grid).datagrid(getData).rows.length - 1) {
textControl.combogrid(grid).datagrid(selectRow, index + 1);
}
} else {
textControl.combogrid(grid).datagrid(selectRow, 0);
}
},
enter: function () { //【回车键】押下处理
textControl.combogrid(hidePanel);
var selected = textControl.combogrid(grid).datagrid(getSelected);
if (selected) {
valueControl.val(UTIL.getJsonByKey(selected, idFild));
textControl.val(UTIL.getJsonByKey(selected, textField));
}

},
query: function (keyword) { //【动态搜索】处理
//设置查询参数
var queryParams = textControl.combogrid("grid").datagrid(options).queryParams;
queryParams.keyword = keyword;
textControl.combogrid("grid").datagrid(options).queryParams = queryParams;
//重新加载
textControl.combogrid("grid").datagrid("reload");
textControl.combogrid("setValue", keyword);
}
},
mode: remote,
fitColumns: true
});
}
});

}
});

 

以上是关于jquery extend 多个扩展方法的主要内容,如果未能解决你的问题,请参考以下文章

jQuery.extend()jQuery.fn.extend()扩展方法示例详解

jQuery.extend 函数详解

jquery 的extend的方法

jQuery中的$.extend方法来扩展JSON对象及合并,方便调用对象方法

为Jquery类和Jquery对象扩展方法

jQuery使用(十四):extend()方法