Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MVC 3返回多个Flot图_Javascript_Json_Asp.net Mvc 3_C# 4.0_Flot - Fatal编程技术网

Javascript MVC 3返回多个Flot图

Javascript MVC 3返回多个Flot图,javascript,json,asp.net-mvc-3,c#-4.0,flot,Javascript,Json,Asp.net Mvc 3,C# 4.0,Flot,谢谢你的阅读。随着我逐渐向MVC迈进,我也越来越多地接触到大量Javascript(我在这方面非常薄弱) 我有一个视图,它呈现一个如下所示的数据列表 <table> <tr> <th>heading 1</th> <th>heading 2</th> <th>heading 3</th> <th>heading 4&l

谢谢你的阅读。随着我逐渐向MVC迈进,我也越来越多地接触到大量Javascript(我在这方面非常薄弱)

我有一个视图,它呈现一个如下所示的数据列表

<table>
    <tr>
        <th>heading 1</th>
        <th>heading 2</th>
        <th>heading 3</th>
        <th>heading 4</th>
        <th>chart</th>
    </tr>
    foreach(var item in Model)
    {
        <tr>
            <td>@item.data1</td>
            <td>@item.data2</td>
            <td>@item.data3</td>
            <td>@item.data4</td>
            <td><div id="graphname"></div> </td>
        </tr>
    }
</table>

标题1
标题2
标题3
标题4
图表
foreach(模型中的var项目)
{
@项目1.1
@项目1.2
@项目1.3
@项目1.4
}
通过下面的例子,我可以得到正确的数据。如何使用从该链接中学到的知识,并能够创建/返回多个图形

因为它是由id引用的?或者有更好的方法完全做到这一点吗?

您需要为每个div设置一个唯一的ID

你可以用几种不同的方法来做。最干净的方法是以某种方式将其绑定到数据,例如,如果每个项的item.data1是唯一的值(如主键),则可以执行以下操作

int i = 0;
foreach(var item in Model)
{
    <tr>
        <td>@item.data1</td>
        <td>@item.data2</td>
        <td>@item.data3</td>
        <td>@item.data4</td>
        <td><div id="@(graphname + i)"></div> </td>
    </tr>
    ++i;
}