I'm having some trouble with scoping in javascript. I'm using a jquery plugin to write a class that is a wrapper for our dropdown controls.
the problem is in the loadJsonList function, the call to this.addOption(s.itemValue, s.itemText); does not work as the method doesn't exist. I know JS has odd scoping but I've no idea how i can run that function in that scope??
jQuery.Class.extend("DDL",
{
id: '',
isTelerik: false
},
{
init: function (newid) {
this.Class.id = newid;
},
getValue: function () {
return $('#' + this.Class.id).val();
},
getText: function () {
return $('#' + this.Class.id + ' :selected').text();
},
setValue: function (newValue) {
try {
$('#' + this.Class.id).val(newValue);
} catch (err) {
alert(err);
}
},
setText: function (newText) {
try {
$('#' + this.Class.id + ' :selected').text(newText);
} catch (err) {
alert(err);
}
},
loadJsonList: function (list, param1, param2, param3) {
this.clearItems();
//init the service
var j = new JsonRPC();
// get the cut down data table
var dt = j.getDropDownData(list, param1, param2, param3);
// parse the datatable and load it into the telerik combo box
jQuery.each(dt, function (i, s) {
this.addOption(s.itemValue, s.itemText);
});
},
addOption: function (value, text) {
$('#' + this.Class.id).append('<option value="' + value + '">' + text + '</option>');
},
removeOption: function (value) {
$('#' + this.Class.id + ' option[value="' + value + '"]').remove();
},
clearItems: function () {
$('#' + this.Class.id + ' option').remove();
}
});
thisyou're not talking about scoping but binding.