Я пытаюсь разобраться с массивами и использую с ними операторы IF.
У меня есть мой массив:
var queryAlias = $('.TableQuery > tbody > tr').map(function () {
var $td2 = $(this).children('td');
return `${$td2.eq(2).html()}([${$td2.eq(0).html()}].[${$td2.eq(1).html()}]) AS ${$td2.eq(4).html()}`;
}).get().join(', '); /* COUNT([TABLE].[FIELD]) AS ALIAS */
Массив берет данные из некоторых столбцов в моей таблице, но сейчас я хочу запустить массив и построить строку на основе Следующее условие, если столбец 3 пуст, а затем добавить строку 1 и 2 тоже строку:
$.each(queryAlias, function (index, value) {
if ((`${queryAlias}`) == null) {
queryAlias[index] = queryAlias[index];
}
});
var field = $("#qBuilerFields option:selected").text();
var table = $("#qBuilerMaintable option:selected").text();
var orderby = $("#qBuilerSortBy option:selected").val();
var expression = $("#qBuilerExpression option:selected").val();
var alias = $("#alias").val();
/* Add new row to table with customers choices */
if ($("#qBuilerExpression").val() == null) {
var addToTable = "<tr style='table-layout: fixed; width: 25%'><td>" + table + "</td><td>" + field + "</td><td style='table-layout: fixed; width: 25%'>" + expression + "</td><td style='table-layout: fixed; width: 25%'>" + orderby + "</td><td style='table-layout: fixed; width: 25%'>" + "[" + field + "]" + "</td><td><p style='color: darkred; text - align: center' class='pointer RemoveUser'>✖</p></td></tr>";
$("table tbody").append(addToTable);
} else {
var addToTable = "<tr style='table-layout: fixed; width: 25%'><td>" + table + "</td><td>" + field + "</td><td style='table-layout: fixed; width: 25%'>" + expression + "</td><td style='table-layout: fixed; width: 25%'>" + orderby + "</td><td style='table-layout: fixed; width: 25%'>" + alias + "</td><td><p style='color: darkred; text - align: center' class='pointer RemoveUser'>✖</p></td></tr>";
$("table tbody").append(addToTable);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Drop down showing tables, this will be table A for any query -->
<select class="select" id="qBuilerMaintable">
<option value="" disabled selected>{ Select Table... }</option>
<option value="">TableA</option>
<option value="">TableB</option>
</select>
<!-- Drop down showing fields linked to table A -->
<select class="select" id="qBuilerFields">
<option value="" disabled selected>{ Select Field... }</option>
<option value="">Field1</option>
<option value="">Field2</option>
</select>
<!-- Alias, this will be the name of the column header if they enter text here -->
<input class="input" id="alias" type="text" placeholder="(optional) Enter Alias... " name="alias" value="" />
<!-- Drop down giving ORDER BY choices -->
<select class="select" id="qBuilerSortBy">
<option value="" disabled selected>{ Select Order By... }</option>
<option value="ASC">Ascending</option>
<option value="DESC">Descending</option>
</select>
<!-- Expression -->
<select class="select" id="qBuilerExpression">
<option value="" disabled selected>{ Select An Expression... }</option>
<option value=""></option>
<option value="count">Count</option>
<option value="sum">Sum</option>
</select>
<table id="t01" class="TableQuery" style="table-layout:fixed">
<thead>
<tr style="table-layout:fixed">
<th style="width:20%">Table</th>
<th style="width:20%">Field</th>
<th style="width:20%">Expression</th>
<th style="width:10%">Order By</th>
<th style="width:20%">Alias</th>
<th style="width:10%">Remove</th>
</tr>
</thead>
<tbody>
<tr style="table-layout:fixed">
</tr>
</tbody>
</table>