javascript - C#多维数组只打印第一个元素
问题描述
我正在尝试将List
变量的内容填充到引导模式。我的问题是代码只显示List
变量的第一个元素。
这是我的代码:
List<string[]> listStatus = new List<string[]>();
for (int i = 0; i < listStatus.Count; i++)
{
for (int j = 0; j < 2; j++)
{
string body = listStatus[i][j+1].ToString();
body = body + " - " + listStatus[i][j].ToString();
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "populateModal('" + body + "');", true);
}
}
ClientScript.RegisterStartupScript(this.GetType(), "Show", "showModal()", true);
附加代码:
protected void btnSplunk_Click(object sender, EventArgs e)
{
string sp_ip = "172.16.159.94";
int sp_port = 22;
string status = CheckCon(sp_ip, sp_port, lblSplunkUpdate);
listStatus.Add(new string[] { status, sp_ip });
}
protected void btnRandom_Click(object sender, EventArgs e)
{
string ran_ip = "134.32.233.21";
int ran_port = 801;
string status = CheckCon(ran_ip, ran_port, lblRnadomUpdate);
listStatus.Add(new string[] { status, ran_ip });
}
有人可以强调我做错了什么并指出我正确的方向吗?
解决方案
所以我重组了代码逻辑并且它起作用了。我没有使用多维数组,而是使用了一个连接字符串。解决方法,但效果很好
List<string> listStatus = new List<string>();
string body = "";
for (int i = 0; i < listStatus.Count; i++)
{
string var = listStatus[i].ToString();
body = body + var + "</br>";
}
Response.Write(body + "</br>");
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "openModal('" + body + "');", true);
ClientScript.RegisterStartupScript(this.GetType(), "Show", "showModal()", true);
JavaScript:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
function openModal(body) {
$("#exampleModalCenter .modal-body").html(body);
}
function showModal() {
$("#exampleModalCenter").modal("show");
}
</script>
推荐阅读
- nginx - nginx重新加载后返回旧数据
- python - 如何在 PULP 中初始化 LPVARIABLE.matrix 的值?
- javascript - 如何通过嵌套的数字键对对象进行排序?
- java - javax.email 是否支持在正文中添加电子邮件签名?
- r - 如何在 ggplot 图形条上方添加百分比?
- r - 如何在ggplot的散点图中显示中间点
- tcl - 在 Tcl 中查找列表元素之间的差异
- google-cloud-platform - 我可以创建的最大计算机引擎 VM 数量是多少?
- javascript - 在 Node 中强制进行垃圾回收以测试 WeakRef 和 FinalizationRegistry
- json - 改造 - 是否有可能期望字符串或对象作为响应