我在javascript中進行範圍設定時遇到了一些麻煩。我正在使用jquery插件編寫一個類,它是我們的下拉控件的包裝。Javascript範圍問題
問題出在loadJsonList
函數中,this.addOption(s.itemValue, s.itemText);
的調用不起作用,因爲該方法不存在。我知道JS有奇怪的範圍,但我不知道如何在該範圍內運行該功能?
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();
}
});
稍微迂腐,談論'this'你不是在談論範圍界定,但結合時。 – slebetman 2010-11-18 03:03:05