【发布时间】:2015-09-17 08:33:17
【问题描述】:
我有一个动态表,我在其中显示一些数据,这些数据的 90% 只是文本,但 10% 是元素。正如您在下面看到的,有一个附有一些 json 的表。例如,json 显示"element_type": ["WAGER_ACTION_BUTTON"] 我需要显示一个按钮,而在另一种情况下,...:"BASIC_CHECKBOX" 然后我需要显示一个复选框。
所以,表格的标题是FILL OPEN,这意味着我需要在那里显示一个按钮。在底部查看 json 对象
这是桌子
<table>
<thead>
<tr>
<th ng-repeat="column in cols"
ng-init="isXX = column.indexOf('XX') === 0">
<span ng-if="isXX">{{column.substring(3).replace('_', ' ')}}</span>
<span ng-if="!isXX">{{column}}</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rows">
<td ng-repeat="column in cols">
<span>{{row[column]}}</span>
</td>
</tr>
</tbody>
</table>
这里是 Angular 部分中的代码
ReportsFactory.pendingBets(reportParam).then(function(data) {
if (data.length) {
gridInfo = _.forEach(data, function(item) {return item;});
$scope.rows = gridInfo;
$scope.cols = Object.keys($scope.rows[0]);
}
}
这是我从后端收到的 json 对象
{
"BET": 57630343,
"CUSTOMER": 181645,
"SPORT": "MLB",
"XX_FILL OPEN": {
"element": {
"element_type": [
"WAGER_ACTION_BUTTON"
],
"element_call": [
"fillOpen(57630343)"
],
"element_content": [
""
]
}
},
"XX_VIEW": null,
"XX_CANCEL": {
"element": {
"element_type": [
"BASIC_CHECKBOX"
],
"element_call": [
""
],
"element_content": [
"0"
]
}
}
}
所以每当你看到一个以XX_ 开头的道具时,就意味着一个元素。
在上面你看到的这个json中,对象键:BET,CUSTOMER,SPORT,XX_FILL_OPEN,XX_VIEW和XX_CANCEL,是表的标题,我在这里重复我自己:每次一个prop以XX_开头,那应该是一个元素,但我需要弄清楚它是什么类型的元素,以便在 DOM 中显示它。
【问题讨论】:
-
我更喜欢为表单元素制作指令
标签: javascript angularjs