Javascript C#仅打印第一个元素的多维数组
我试图将Javascript C#仅打印第一个元素的多维数组,javascript,c#,asp.net,asp.net-mvc,webforms,Javascript,C#,Asp.net,Asp.net Mvc,Webforms,我试图将列表变量的内容填充到引导模式。我的问题是代码只显示列表变量的第一个元素 这是我的代码: List<string[]> listStatus = new List<string[]>(); for (int i = 0; i < listStatus.Count; i++) { for (int j = 0; j < 2; j++) { string bod
列表
变量的内容填充到引导模式。我的问题是代码只显示列表
变量的第一个元素
这是我的代码:
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);
有人能指出我做错了什么,并给我指出正确的方向吗?因此,我重新构造了代码逻辑,它成功了。我没有使用多维数组,而是使用了一个连接字符串。解决方法,但它工作完美
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);
List listStatus=new List();
字符串体=”;
for(int i=0;i”;
}
响应。写入(正文+“”;
RegisterStartupScript(this.GetType(),“Popup”,“OpenModel(““+body+”);”,true);
RegisterStartupScript(this.GetType(),“Show”,“showmodel()”,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>
函数openModal(body){
$(“#exampleModalCenter.modal body”).html(body);
}
函数showmodel(){
$(“#示例ModalCenter”).modal(“显示”);
}
因此,我重新构造了代码逻辑,并且它工作了。我没有使用多维数组,而是使用了一个连接字符串。解决方法,但它工作完美
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);
List listStatus=new List();
字符串体=”;
for(int i=0;i”;
}
响应。写入(正文+“”;
RegisterStartupScript(this.GetType(),“Popup”,“OpenModel(““+body+”);”,true);
RegisterStartupScript(this.GetType(),“Show”,“showmodel()”,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>
函数openModal(body){
$(“#exampleModalCenter.modal body”).html(body);
}
函数showmodel(){
$(“#示例ModalCenter”).modal(“显示”);
}
你打开了很多情态动词???没有意义。您只能使用RegisterStatupScript()一次。这是你的问题。@Jon好的,谢谢你。实际上不知道:不限制您多次使用RegisterStatupScript,但限制您多次注册相同的类型/键组合(这是一项功能,而不是限制)。(正如中所指出的)那不是你正在做的。。。。你在每次迭代中都会创建一个新的主体,并在每次迭代中写出脚本。你打开了很多模态???没有意义。您只能使用RegisterStatupScript()一次。这是你的问题。@Jon好的,谢谢你。实际上不知道:不限制您多次使用RegisterStatupScript,但限制您多次注册相同的类型/键组合(这是一项功能,而不是限制)。(正如中所指出的)那不是你正在做的。。。。您在每次迭代中创建一个新的主体,并在每次迭代中编写脚本。