我正在使用ng-repeat从JSON对象创建一组笔记(div)。卡片的数量由数组中JSON对象的数量决定。Type表示卡片的头部,Content表示卡片的主体。然而,“内容”的内容并不一致。在一些例子中,内容仅仅是一个句子或段落。在另一些情况下,内容是一个数组。当内容是句子时,格式化处理得很好。当内容是一个数组时,我最终以文本格式的实际数组[{"year":"2009", "operation":"caesarean"},{"year":"2010", "operation":"torn meniscus"}]作为卡片的主体。有没有办法在不单独编写每张卡的脚本的情况下实现这一点?
HTML
<section name="patientinfo">
<div align="center" ng-controller="HistoryCtrl">
<div class="grid-container" ng-repeat="record in historyItems">
<div class="row" row>
<div class="col-2" ng-repeat="history in record.History">
<div class="note" draggable="true">
<div class="row" id="rowhead3">
<div class="col-6" >
<span class="note-header">{{history.type}}</span>
</div>
</div>
<div class="row">
<div class="col-6" style="overflow: auto; height:250px;">
<div>
<span class="note-content">
{{history.content}}
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>JSON示例(实际的JSON非常庞大)。除了“历史”之外,还有许多其他的条目。另外,这些笔记不是真人写的,所以不用担心。
"History": [
{
"type": "medical",
"content": [
{
"condition": "IBS"
},
{
"condition": "Torn Meniscus Right Knee"
},
{
"condition": "Seasonal Allergies"
}
]
},
{
"type": "SOCIAL HISTORY",
"content": "Lives with husband and 3 children. No history of violence, domestic violence, or rape. Feels safe at home and in relationship. ETOH on weekends (socially 4 drinks in one weekend occasionally) and occasionally smokes cigarettes and marijuana. Admits to very rare marijuana on special occasions."
}]我最终得到的例子是:http://i.stack.imgur.com/MtuBN.png
发布于 2015-03-27 11:14:07
您应该将数据转换或扩充为一种新的格式,其中每个注释都具有以下结构:
{
type: "string",
contentType: "(text|list)",
content: "string" // OR array of strings
}为此,您将需要自定义逻辑来将数组中的每个对象转换为单个字符串。
然后只需在contentType属性上使用ng-switch来决定使用哪个标记(例如,如果contentType为list,则使用<ul> )。
https://stackoverflow.com/questions/29292532
复制相似问题