开发者

keep getting ".getSelected is not a function"

开发者 https://www.devze.com 2023-02-07 16:19 出处:网络
i\'ve made an HtmlTable.Select in mooto开发者_如何学Pythonols 1.3 of an existing table, tried \"selectable: true\" and \"enableSelect\", nothing works, if i try to access the \"getSelected\"-method of

i've made an HtmlTable.Select in mooto开发者_如何学Pythonols 1.3 of an existing table, tried "selectable: true" and "enableSelect", nothing works, if i try to access the "getSelected"-method of my table, i keep getting ".getSelected is not a function", all other functions like "selectAll" or "selectNone" work perfectly".

my code (from inside my class):

this.options.HTMLTable = new HtmlTable(this.options.table, {
    selectable : true
});

// this works perfect ...  
this.options.HTMLTable.selectAll();

// ... but this causes the error!  
console.log(this.options.HTMLTable.getSelected());

can you help?


I'm not a mooTools expert but if you check this jsfiddle

You will see that in the prototype (.__proto__) of this.options.HTMLTable the method selectAll is defined but getSelected is not.

This is a start to your debugging. Add some data to the fiddle to make it more realistic of your issue.

There's a ._selectedRows property on HTMLTable though. just write your own .getSelected method and be done with it!

I just read the source code and the method getSelected doesn't exist. Here's what it should do

function getSelected() {
    return this._selectedRows;
}

File it as a bug and in the meanwhile just use

// Bug in HtmlTable. Custom implementation. Remove when using mootools 1.4
HtmlTable = new Class({
    Extends: HtmlTable, 
    getSelected: function() {
        return this._selectedRows;
    }
});

As @DimitarChristoff recommended your better off using:

if (!HtmlTable.prototype.getSelected) {
    HtmlTable.prototype.getSelected = function() {
        return this._selectedRows;
    };      
}

This way you only change the prototype of HtmlTable if it's neccessary. You might need some kind of HtmlTable.Select is loaded check.

See new fiddle

0

精彩评论

暂无评论...
验证码 换一张
取 消