我有以下代码可以很好地工作,但是我可以使用quantityAllowed使下拉菜单动态化,作为下拉菜单的最大值。目前我已经为每个打印添加了10个选项,但我更喜欢的是丢弃菜单只有正确的数量。我认为我需要的循环将选择开始使用循环的值,但当我我试过,我只是得到一个错误,所以我知道我做错了什么。
UITabBarController
答案 0 :(得分:2)
您可以将您的HTML生成代码与jQuery DOM分配分开。这使得它更容易阅读和操作。当您进入选择/选项区域时,将其放入for ...循环以生成适当数量的选项。
providers: [ SharedService ]
function arrayData() {
var index;
var text = "<ul>";
var htmlTable = '';
var calcTable = [];
calcTable = [
{ printName:"Name1", printPrice:8000000, quantityAllowed:6},
{ printName:"Name2", printPrice:12000000, quantityAllowed:5},
{ printName:"Name3", printPrice:20000000, quantityAllowed:4},
{ printName:"Name4", printPrice:2000000, quantityAllowed:3},
];//end of array
for (index = 0; index < calcTable.length; index++) {
var myclass = 'class="printwant"';
var output = '';
output += "<tr>";
output += "<td style='padding:0px 0px 0px 36px;'>" + calcTable[index].printName + "</td>";
output += "<td class='printpoints'>" + calcTable[index].printPrice + "</td>";
output += "<td>" + calcTable[index].quantityAllowed + "</td>";
output += "<td><select " + myclass + ">";
for( var i=0, x=calcTable[index].quantityAllowed; i<x; i++ ){
output += '<option value="' + i + '">' + i + '</option>';
}
output += "</select></td><td></td> </tr>";
$("#tbNames tr:last").after(output);
}//end of loop
$("#tbNames tr:last").after("<tr>" + "<td colspan = '5' height=40 > </tr>");
}
arrayData();