简体   繁体   中英

javascript syntax error setting property of jquery datatable

I am using the jquery data table like this:

$.fn.tkDataTable = function(){
        "order": [[ 7, 'asc' ]]

        if (! this.length) return;

        if (typeof $.fn.dataTable != 'undefined') {

            this.dataTable();

        }

    };

I get the error:

Uncaught SyntaxError: Unexpected token :

I get this on the line with "order". How can I correctly set this attribute without the syntax error?

You rarely call datatable without an options object

I suspect what you want is something like

$.fn.tkDataTable = function(){
    var opts = {
       "order": [[ 7, 'asc' ]],
       //...  other initialization properties
    };

    if (! this.length) return;

    if (typeof $.fn.dataTable != 'undefined') {
        // pass options to plugin
        this.dataTable(opts);

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM