Skip to content

Instantly share code, notes, and snippets.

@carlosanders
Last active February 12, 2017 15:18
Show Gist options
  • Save carlosanders/b32963d426ddc7374a34dc76a4de12f5 to your computer and use it in GitHub Desktop.
Save carlosanders/b32963d426ddc7374a34dc76a4de12f5 to your computer and use it in GitHub Desktop.
Plugin para retornar a row do item selecionado na combobox do jQuery EasyUI
/**
* @description The plugin returns the JSON of the combobox the jQuery EasyUI
* @author Carlos Anders
* @link http://www.andershost.com.br
*/
(function ($) {
$.extend($.fn.combobox.methods, {
/**
* The method returns the data in the JSON object of the
* selected item in the combobox
* @param jq - Object jQuery
* @returns JSON {"key": "value"}
* @example $('#cb').combobox('getRow') return all the selected item
* $('#cb').combobox('getRow').id - return specific item
* $('#cb').combobox('getRow').desc - return specific item
*/
getRow: function (jq) {
var opts = $.data(jq[0], 'combobox').options;
var data = $.data(jq[0], 'combobox').data;
var value = jq.combobox('getValue');
var item = $.grep(data, function (row) {
if (row[opts.valueField] == value) {
return true;
} else {
return false;
} // if
}); //item
return item[0];
}, // getRow
/**
* @description Returns the object's keys
* @param jq - Object jQuery
* @returns {Array} - ["id", "text", "selected", "desc"]
* @example $('#cb').combobox('getKeys') - return all keys the selected item
* $('#cb').combobox('getKeys')[0] - return specific key
*/
getKeys: function (jq) {
var obj = jq.combobox('getRow');
var keys = [];
$.map(obj, function (element, index) {
keys.push(index);
}); //map
return keys;
} //getKeys
}); //methods
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment