我有一个包含行的数据库表。基于表行,我想动态创建div标签。我的要求就像我必须根据数据库行数创建div。
第一个div应该在第二个div旁边。
以下是我正在使用的javascript函数:
Prelude> take 10 l1
[[1,-1],[2,-2],[3,-3],[4,-4],[5,-5],[6,-6],[7,-7],[8,-8],[9,-9],[10,-10]]
Prelude> take 10 l2
[1,-1,2,-2,3,-3,4,-4,5,-5]
我已经写出了逻辑,但22行只创建了一个div标签。 我想在1 div中显示10条记录,在第2 div中显示另外10条记录,依此类推。
答案 0 :(得分:1)
您的解决方案
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import com.github.tomakehurst.wiremock.WireMockServer;
public class WireMockTest {
public static void main(String[] args) throws InterruptedException {
WireMockServer wireMockServer1 = new WireMockServer();
wireMockServer1.start();
wireMockServer1.stubFor(get(urlEqualTo("/testWireMock"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain")
.withStatus(200).withBody("Welcome to WireMock!")));
System.out.println("Server started");
Thread.sleep(1000);
wireMockServer1.stop();
}
}
$('#rows').change(function(e) {
var rows_count = parseInt($(this).val());
var div_count = Math.ceil(rows_count/10);
resultHtml = '<table width="100%" border="1px"><tr>';
j=0;l=0;
for (var i = 1; i<=div_count ; i++){k=0;
if(l==4){ resultHtml += '</tr><tr>';l=0;}
resultHtml += '<td align="center">';
while((j<rows_count)&&(k<10)){ resultHtml += '<input type="name" placeholder="text goes here..."><br>';j++;k++;}
resultHtml += '</td>';
l++;
}
resultHtml += '</tr></table>';
$('#inputs').html(resultHtml);
});