我有静态表
<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/