itemsByValue method

This commit is contained in:
vitalets
2012-12-28 18:05:09 +04:00
parent 5f3f820312
commit d4d2bf930a
7 changed files with 47 additions and 28 deletions

View File

@@ -94,11 +94,8 @@ $(function(){
//collect text of checked boxes
value2htmlFinal: function(value, element) {
var html = [],
/*jslint eqeq: true*/
checked = $.grep(this.sourceData, function(o){
return $.grep(value, function(v){ return v == o.value; }).length;
});
/*jslint eqeq: false*/
checked = $.fn.editableutils.itemsByValue(value, this.sourceData);
if(checked.length) {
$.each(checked, function(i, v) { html.push($.fn.editableutils.escape(v.text)); });
$(element).html(html.join('<br>'));

View File

@@ -236,20 +236,7 @@ List - abstract class for inputs that have source option loaded from js array or
});
}
return result;
},
//search for item by particular value
itemByVal: function(val) {
if($.isArray(this.sourceData)) {
for(var i=0; i<this.sourceData.length; i++){
/*jshint eqeqeq: false*/
if(this.sourceData[i].value == val) {
/*jshint eqeqeq: true*/
return this.sourceData[i];
}
}
}
}
}
});

View File

@@ -47,10 +47,13 @@ $(function(){
},
value2htmlFinal: function(value, element) {
var text = '', item = this.itemByVal(value);
if(item) {
text = item.text;
var text = '',
items = $.fn.editableutils.itemsByValue(value, this.sourceData);
if(items.length) {
text = items[0].text;
}
Select.superclass.constructor.superclass.value2html(text, element);
},