EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on March 01, 2013, 04:00:49 AM



Title: push to data array onLoadSuccess [solved]
Post by: devnull on March 01, 2013, 04:00:49 AM
I am trying to push a row to the combobox after it has loaded it's data when the element's "all" attribute is set.

The data gets appended, however I am unable to push this data back to the combobox as it results in recursion with onLoadSuccess.

How can I achieve this ??

Code:
<label>Employee</label><input type="text" name="userid" class="easyui-combobox fkey" url="/intra/php/dget.php?_id_=userid" all="y"></input>

Code:
$.extend($.fn.combobox.defaults, { valueField: 'val',textField: onLoadSuccess:cbOnLoad});

function cbOnLoad(data){
if($(this).attr('all')){
data.push({txt:'All',val:'*',selected:true});
$(this).combobox('loadData',data);
}
}




Title: Re: push to data array onLoadSuccess
Post by: devnull on March 01, 2013, 05:35:01 AM
solved by pushing to first element and then checking if Exists:

Code:
function cbOnLoad(data){
if($(this).attr('all')){
if(data[0].txt != 'All') {
data.unshift({txt:'All',val:'*',selected:true});
$(this).combobox('loadData',data);
}

}
}

Is there a better / more efficient method ??