javascript - Angular 表到 json

标签 javascript json angularjs

我有静态表

<table class="table" at-table at-list="List">
        <tr>
            <td at-attribute="name"  >Date and Time of Incident</td>
            <td at-attribute="values">{{info.dt}}</td>
        </tr>
        <tr>
            <td at-attribute="name"  >Reported By</td>
            <td at-attribute="values">{{info.reportedby}}</td>
        </tr>
        <tr>
            <td at-attribute="name"  >Company of Reporter</td>
            <td at-attribute="values">{{info.company}}</td>
        </tr>
<table>

如何从此表创建以下 Json?

{"fields":[

 {"name":"Date and Time of Incident","values":["2013-05-13T15:40:00"]},

 {"name":"Reported By","values":["John Doe"]},

 {"name":"Company of Reporter","values":["CompanyA"]}]
}

指令 Angular 表 https://github.com/samu/angular-table无法在对象列表中收集信息

最佳答案

我对你的问题有点困惑,但你为什么不将数据放入 Controller 的数组中,然后在 HTML 中使用 Angular 的 ngRepeat 函数?

Controller .js

$scope.fields = [
    {"name":"Date and Time of Incident","values":["2013-05-13T15:40:00"]},
    {"name":"Reported By","values":["John Doe"]},
    {"name":"Company of Reporter","values":["CompanyA"]}];

index.html

<table>
  <tbody>
    <tr ngRepeat="field in fields">
      <td>{{data.name}}</td>
      <td>{{data.value}}</td>
    </tr>
  </tbody>
</table>

表格数据是否可编辑?如果是这样,请尝试使用下面的代码。

<td><input type="text" ngModel="field.name" /></td>
<td><input type="text" ngModel="field.name" /></td>

一旦你有了这些数据,你就可以在 Controller 中随意操作它,或者将它传递给一个更好的服务。

关于javascript - Angular 表到 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21665367/

相关文章:

javascript - 如何在 Express 中设置 json 响应的路由?

javascript - JQuery 在点击时遍历 DOM

javascript - 单击 esc 按钮时,不应关闭甜蜜警报

javascript - 计算路线的距离

javascript - 表达 router.get() 函数语法错误

javascript - AngularJS:动态编译指令

javascript - 如何为 Azure 表存储 REST 请求生成 SharedKeyLite

json - dust.js 键中的特殊字符?

python - 如何在 python 中通过 jsonschema 过滤 json

javascript - 如何自定义 Angular 谷歌图表图例信息