【问题标题】:Bind Angular with dynamic data from database将 Angular 与数据库中的动态数据绑定
【发布时间】:2014-07-23 09:46:47
【问题描述】:

我对 Angularjs 很陌生,我想实现一个类似于这个 jsfiddel http://jsfiddle.net/NfPcH/93/ 的可编辑表(从官方 angular 文档中检索)但是我如何用数据列表填充表而不是硬编码数据从 MVC 或 ViewBag 中的数据库中检索?

例如,而不是下面的这个 MVC 表,我想实现相同的目标,而是使用 Angular 来使表可编辑。

@if (ViewBag.Session != null)
{
<table class="table table-hover">
     <tr>
        <th>
            ID
        </th>
        <th>
            Name
        </th>
        <th>
            Surname
        </th>
        <th>
            House
        </th>
        <th>
            Address
        </th>
        <th>
            Locality
        </th>
        <th>
            Contact
        </th>
        <th>
            Contact 2
        </th>
        <th>
            Contact 3
        </th>
        <th>
            Reply
        </th>
        <th>
            Edit
        </th>
    </tr>
    @foreach (var item in ViewBag.Session)
    {
    <tr>
        <td>
            @item.ID
        </td>
        <td>
            @item.Name
        </td>
        <td>
            @item.Surname
        </td>
        <td>
            @item.House
        </td>
        <td>
            @item.Address
        </td>
        <td>
            @item.Locality
        </td>
        <td>
            @item.Contact1
        </td>
        <td>
            @item.Contact2
        </td>
        <td>
            @item.Contact3
        </td>
        <td>
            @item.Reply
        </td>
    </tr>
    }
</table>

另外,当一行发生变化并保存时,如何将数据发送回后台保存到数据库中?

【问题讨论】:

标签: mysql asp.net-mvc angularjs model-view-controller


【解决方案1】:

我认为阅读快速入门教程、培训或书籍对您来说是个好主意。

这里有一个链接,可以开始在服务器端使用 web api 以及在客户端使用 angularjs,它只是从服务器加载项目列表。

http://www.youtube.com/watch?v=Ja2xDrtylBw

【讨论】:

    猜你喜欢
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2023-04-02
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    相关资源
    最近更新 更多