我想显示附件部分的表格格式。我有查找和结果数据。两者都有一个共同的列attachmentTypeId
。我想根据 id 显示附件类别描述。在ng-bind
我尝试过的尝试中,它没有用。
我在 中使用一个函数ng-bind
,希望该方法是错误的,期待该方法的替代方法。
attachmentLookup
包含attachmentDesc
, _attachmentTypeId
$scope.attachmentLookup = [{
"attachmentDesc": "Category One",
"attachmentTypeId": "1"
}, {
"attachmentDesc": "Category Two",
"attachmentTypeId": "2"
}, {
"attachmentDesc": "Category Three",
"attachmentTypeId": "3"
}, {
"attachmentDesc": "Category Four",
"attachmentTypeId": "4"
}, {
"attachmentDesc": "Category Five",
"attachmentTypeId": "5"
}];
attachmentDetails
来自数据库的数据为,
$scope.attachmentDetails = [{
"attachmentId": "001",
"fileName": "File Name 001",
"attachmentTypeId": "1"
}, {
"attachmentId": "003",
"fileName": "File Name 003",
"attachmentTypeId": "2"
}, {
"attachmentId": "005",
"fileName": "File Name 005",
"attachmentTypeId": "3"
}, {
"attachmentId": "007",
"fileName": "File Name 007",
"attachmentTypeId": "1"
}, {
"attachmentId": "009",
"fileName": "File Name 009",
"attachmentTypeId": "2"
}, {
"attachmentId": "011",
"fileName": "File Name 011",
"attachmentTypeId": "3"
}];
HTML代码为,
<table>
<thead>
<tr>
<th>File Name</th>
<th>|</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="attachment in attachmentDetails">
<td> <span ng-bind="attachment.fileName"></span>
</td>
<td>|</td>
<td> <span ng-bind="getCatgoryName(attachment.attachmentTypeId)"></span>
</td>
</tr>
</tbody>
</table>
getCatgoryName
来自控制器的代码是,
$scope.getCatgoryName = function (attachmentTypeId) {
angular.forEach($scope.attachmentLookup, function (attachemnt) {
if (attachemnt.attachmentTypeId === attachmentTypeId)
return attachemnt.attachmentDesc;
});
};
Plunker 示例:http: //plnkr.co/edit/dZy5gW4q9CxWF2NszXYc