EasyUI Forum
May 12, 2024, 12:54:02 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Howto add items to a combobox dynamically?  (Read 7272 times)
ejzhang
Jr. Member
**
Posts: 61



View Profile
« on: March 18, 2015, 06:34:32 PM »

I want to add items to a combobox dynamically many times in scripts, and keep the items before added.
How can i do? thanks very much!
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 18, 2015, 08:36:50 PM »

Please extend an 'appendItem' method to achieve this functionality.
Code:
$.extend($.fn.combobox.methods, {
appendItem: function(jq, item){
return jq.each(function(){
var state = $.data(this, 'combobox');
var opts = state.options;
var items = $(this).combobox('getData');
items.push(item);
$(this).combobox('panel').append(
'<div id="' + state.itemIdPrefix+'_'+(items.length-1) + '"  class="combobox-item">' +
(opts.formatter ? opts.formatter.call(this, item) : item[opts.textField]) +
'</div>'
)
})
}
})

Usage example:
Code:
$('#cc').combobox('appendItem', {
  id: '12',
  text: 'text12'
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!