Ich versuche, die ID-Werte von dynamisch erstellten Eingaben innerhalb einer dynamisch erstellten Tabelle mit dem folgenden Code zu setzen. Logischerweise versuche ich, die ID als table.description + i (z.B. V1, F1) zu setzen, aber es erlaubt nicht, dass die Tabellen korrekt erstellt werden, und die Konsole zeigt nur newInput.id für jede Iteration. Wie kann ich einen ID-Wert zuweisen, der mit der Beschreibung und dem Iteratorwert übereinstimmt?Wie setze ich input.id auf dynamisch erzeugte Eingänge
Dank
function addBaseTable() {
var BaseTable = [
{"description": "V", input1: true, "specification": "Pass/Fail", input2: false, input3: false, input4: true,"result": "Pass",input5: true},
{"description": "F",input1: true,"specification": "≥ " + fSpec + "mL/min<br>" +flowAmtMin ,input2: true,input3: true,input4: true,"result": "Pass",input5: true},
{"description": "BP",input1: true,"specification": "≥ " + bpSpec + " psi <br>RV:Spec "+bpRV+" ",input2: true,input3: true,input4: true,"result": "Pass",input5: true},
{"description": "RP",input1: true,"specification": "≤ " + rpSpec + "",input2: true,input3: true,input4: true, "result":"Pass",input5: true},
{"description": "V2",input1: true,"specification": "≥ " + v2Spec + " ",input2: false,input3: false,input4: true,"result": "Pass",input5: true},
{"description": "HB",input1: true,"specification": '≥ +' + bSpec + ' psi <br>RV:',input2: false,input3: false,input4: true,"result": "Pass",input5: true},
{"description": "SD",input1: true,"specification": '≤ ' + sdSpec + ' <br>RV: 0 Range ',input2: true,input3: true,input4: true,"result": "Pass",input5: true},
{"description": "P",input1: true,"specification": "< 0",input2: false,input3: false,input4: true,"result": "Pass",input5: true}
];
var allRows = [];
for (var i = 0; i < IV5BaseTable.length; i++) {
var row = "<tr>" + "<td>" + BaseTable[i].description + "</td>" +
"<td>" + createInput(BaseTable[i].input1,BaseTable,i) + "</td>" +
"<td>" + BaseTable[i].specification + "</td>" +
"<td>" + createInput(BaseTable[i].input2,BaseTable,i) + "</td>" +
"<td>" + createInput(BaseTable[i].input,BaseTable,i3) + "</td>" +
"<td>" + createInput(BaseTable[i].input4,BaseTable,i) + "</td>" +
"<td>" + BaseTable[i].result + "</td>" +
"<td>" + createInput(BaseTable[i].input5,BaseTable,i) + "</td>" + "</tr>";
allRows.push(row);
}
var tableRef = document.getElementById("tBodyTestTable");
tableRef.innerHTML = allRows.join(" ");
}
//Pass True||False, the Table, and the row number
function createInput(val,table, i){
var opt = {
true: function(){
var newInput = '<input type="text" class="testingField"/>';
newInput.id = "table.description" + i ;
return newInput;
},
false: function(){
return "N/A"
}
};
return opt[val]();
}
Sie legen die ID-Eigenschaft einer Zeichenfolge fest. Wenn Sie ein tatsächliches '' Element wollen, verwenden Sie' document.createElement ('input') '. –