Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Помогите уменьшить содержимое функции (https://javascript.ru/forum/misc/74344-pomogite-umenshit-soderzhimoe-funkcii.html)

Nexus 03.07.2018 15:24

Мои 5 копеек на основе кода Manyasha:
function createTable(data, str) {
    var data_st = [{
            color: "#bad7ff",
            btn_class: "btn-ioj",
            id: "infoOrderJournal",
            stat: "Оформление"
        }, {
            color: "#a0f0f7",
            btn_class: "btn-woj",
            id: "warningOrderJournal",
            stat: "Исполнение"
        }],
        cellsFields = ['cod', 'nr', 'or', 'np', 'op', 'is', 'vr'],
        html = data.map(function(row) {
            if (
                [0, 1].indexOf(row.st) < 0 ||
                !((str == 3 && data[i].is == 'текст1') || (str == 4 && data[i].is == 'текст2') || (str != 3 && str != 4))
            )
                return;


            var td = data_st[row.st];
            return '<tr class="trTOJ">' +
                  cellsFields.map(function(key) {
                      return '<td bgcolor="' + td.color + '">' + row[key] + '</td>'
                  }).join('\n') +
                  '<td class="btn btn-info ' + td.btn_class + '" ' +
                      'id="' + td.id + '" data1="' + row.nr + '" data2="' + row.prim + '">' + td.stat '</td>' +
                '</tr>';
        }).join('');

    $('#table').html(html);
}

Artur_Hopf 04.07.2018 09:56

Nexus,
Это слишком круто, тяжело вспомнить будет через пол годика что тут происходит =)


Часовой пояс GMT +3, время: 15:40.