Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

Why there is a prefix like sDom, oLanguage in jQuery Datatable?

I am using a dataTable which I've initiated with,

var datatable = $('#datatble').DataTable({
    ... (Some stuff around there)
    oLanguage: {
        sSearch: '_INPUT_'
        lengthMenu: '_MENU_',
    },
    language: {},
    sDom: '',
});

My question is why there is a prefix for properties like sDom, oLanguage, sSearch?

Without language: {}, the lengthMenu property did not work. Without the prefix, that corresponding property didn't work.

Please explain me, why is this happening?

What are those prefix are meant?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

DataTables has two naming standards:

  • older Hungarian notation names (for versions prior to 1.10)
  • newer camelCase names (from 1.10 onwards)

If you are using the latest version of DataTables (from version 1.10 onwards), you can use either the new naming standard or the old one.

There is a page in the official documentation which documents the mapping between the two naming standards.

The new 1.10+ API is bigger than the old (pre-1.10) API, so there are some cases where there is no older Hungarian-style equivalent for the newer camelCase names.

Looking at one of the examples in your question:

oLanguage: {
  sSearch: '_INPUT_',
  lengthMenu: '_MENU_',
}

There is no such property as oLanguage.lengthMenu - it has to be:

  • sLengthMenu if you are using oLanguage (old style)
  • lengthMenu if you are using language (new style)

I would recommend using the new names wherever possible - especially on new projects. The Hungarian notation option is deprecated and will be removed in future versions. But you will see the old names used by a lot of older examples and tutorials.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...