MethodName不是Javascript中的函数
在MethodName不是Javascript中的函数,javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,在loadComplete方法中的以下代码中,它给出了此错误: this.getColumnIndexByName不是函数 dataGrid.prototype={ 显示:函数(){ var html=[]; var检查=0; html.push(“\n”); $('body').append(html.join(“”); $(“#”+this.id).jqGrid({ url:“index.jsp”, styleUI:'引导', 数据类型:“本地”, 数据:这个数据, colModel:thi
loadComplete
方法中的以下代码中,它给出了此错误:
this.getColumnIndexByName不是函数
dataGrid.prototype={
显示:函数(){
var html=[];
var检查=0;
html.push(“\n”);
$('body').append(html.join(“”);
$(“#”+this.id).jqGrid({
url:“index.jsp”,
styleUI:'引导',
数据类型:“本地”,
数据:这个数据,
colModel:this.getColModels(this.data[0]),
viewrecords:是的,
宽度:1300,
身高:250,
rowNum:50,
loadComplete:function(){
var iCol=this.getColumnIndexByName('Enable');
var rows=$(“#”+this.id).jqGrid('getGridParam','records');
var i;
对于(i=0;i
您需要在正确的this
dataGrid.prototype = {
// ...
display : function() {
var me = this; // Keep a reference to the dataGrid `this`
// ...
$("#" + me.id).jqGrid({
// ...
loadComplete: function () {
var iCol = me.getColumnIndexByName('Enable');
您需要在正确的
this
dataGrid.prototype = {
// ...
display : function() {
var me = this; // Keep a reference to the dataGrid `this`
// ...
$("#" + me.id).jqGrid({
// ...
loadComplete: function () {
var iCol = me.getColumnIndexByName('Enable');
由于此内部
loadComplete
未引用对象,因此调用此行为
看看其他有趣的文章
您必须将此引用保存到另一个变量并使用它:
dataGrid.prototype = {
display : function() {
var self = this; // Save this reference
var html = [];
var check = 0;
html.push("<table id='"+this.id+"" + "'class='table'>\n</table>");
$('body').append(html.join(""));
$("#" + this.id).jqGrid({
url : "index.jsp",
styleUI : 'Bootstrap',
datatype : "local",
data : this.data,
colModel : this.getColModels(this.data[0]),
viewrecords : true,
width : 1300,
height : 250,
rowNum : 50,
loadComplete: function () {
//use selft reference
var iCol = self.getColumnIndexByName('Enable');
var rows = $("#" + self.id).jqGrid('getGridParam', 'records');
var i;
for (i = 0; i < rows; i ++) {
$(rows[i].cells[iCol]).click(function (e) {
var id = $(e.target).closest('tr')[0].id, isChecked = $(e.target).is(':checked');
alert("checked:" + isChecked);
//you can also get the values of the row data
alert('clicked on the checkbox in the row with id=' + id + '\nNow the checkbox is ' + (isChecked ? 'checked' : 'not checked'));
});
}
}
});
},
getColNames : function(data) {
var keys = [];
for ( var key in data) {
if (data.hasOwnProperty(key)) {
keys.push(key);
}
}
return keys;
},
getColModels : function(data) {
var colNames = this.getColNames(data);
var colModelsArray = [];
var str2;
for (var i = 0; i < colNames.length; i++) {
var str1;
str1 = {
name : colNames[i],
index : colNames[i],
};
colModelsArray.push(str1);
}
str2 = {
name : 'Enable',
index : 'Enable',
};
colModelsArray.push(str2);
return colModelsArray;
},
getColumnIndexByName : function (columnName) {
var cm = $("#" + this.id).jqGrid('getGridParam', 'colModel'), i, l;
for (i = 0, l = cm.length; i < l; i += 1) {
if (cm[i].name === columnName) {
return i;
}
}
return -1;
},
};
dataGrid.prototype={
显示:函数(){
var self=this;//保存此引用
var html=[];
var检查=0;
html.push(“\n”);
$('body').append(html.join(“”);
$(“#”+this.id).jqGrid({
url:“index.jsp”,
styleUI:'引导',
数据类型:“本地”,
数据:这个数据,
colModel:this.getColModels(this.data[0]),
viewrecords:是的,
宽度:1300,
身高:250,
rowNum:50,
loadComplete:函数(){
//使用自参考
var iCol=self.getColumnIndexByName('Enable');
var rows=$(“#”+self.id).jqGrid('getGridParam','records');
var i;
对于(i=0;i
由于此内部loadComplete
未引用对象,因此调用此行为
看看其他有趣的文章
您必须将此引用保存到另一个变量并使用它:
dataGrid.prototype = {
display : function() {
var self = this; // Save this reference
var html = [];
var check = 0;
html.push("<table id='"+this.id+"" + "'class='table'>\n</table>");
$('body').append(html.join(""));
$("#" + this.id).jqGrid({
url : "index.jsp",
styleUI : 'Bootstrap',
datatype : "local",
data : this.data,
colModel : this.getColModels(this.data[0]),
viewrecords : true,
width : 1300,
height : 250,
rowNum : 50,
loadComplete: function () {
//use selft reference
var iCol = self.getColumnIndexByName('Enable');
var rows = $("#" + self.id).jqGrid('getGridParam', 'records');
var i;
for (i = 0; i < rows; i ++) {
$(rows[i].cells[iCol]).click(function (e) {
var id = $(e.target).closest('tr')[0].id, isChecked = $(e.target).is(':checked');
alert("checked:" + isChecked);
//you can also get the values of the row data
alert('clicked on the checkbox in the row with id=' + id + '\nNow the checkbox is ' + (isChecked ? 'checked' : 'not checked'));
});
}
}
});
},
getColNames : function(data) {
var keys = [];
for ( var key in data) {
if (data.hasOwnProperty(key)) {
keys.push(key);
}
}
return keys;
},
getColModels : function(data) {
var colNames = this.getColNames(data);
var colModelsArray = [];
var str2;
for (var i = 0; i < colNames.length; i++) {
var str1;
str1 = {
name : colNames[i],
index : colNames[i],
};
colModelsArray.push(str1);
}
str2 = {
name : 'Enable',
index : 'Enable',
};
colModelsArray.push(str2);
return colModelsArray;
},
getColumnIndexByName : function (columnName) {
var cm = $("#" + this.id).jqGrid('getGridParam', 'colModel'), i, l;
for (i = 0, l = cm.length; i < l; i += 1) {
if (cm[i].name === columnName) {
return i;
}
}
return -1;
},
};
dataGrid.prototype={
显示:函数(){
var self=this;//Sa