【发布时间】:2017-05-23 19:30:27
【问题描述】:
这就是我的布局在 html 中的样子
<div ng-repeat="message in messages">
<div ng-class="{'messages messages--sent': userId == message.id,
'messages messages--received': userId != message.id}">
<div class="message">
{{message.content}}
</div>
</div>
</div>
这是我的消息数组的结构
$scope.messages = [
{
"id":"Michael",
"content":"Hey"
},
{
"id":"Rich",
"content":"Yow"
},
{
"id":"Rich",
"content":"How are you"
},
{
"id":"Michael",
"content":"Im okay"
},
{
"id":"Michael",
"content":"Im missed you!"
},
];
This is the layout I'm trying to achieve
之前的布局遵循这个 css 代码样式
.messages--received .message:first-child {
border-top-left-radius: 50px;
}
.messages--received .message:last-child {
border-bottom-left-radius: 50px;
margin-bottom: 10px;
}
.messages--received .message:last-child::after {
content: " ";
display: block;
background: url(profile.png) center center no-repeat;
border-radius: 50%;
height: 30px;
width: 30px;
position: absolute;
bottom: 0;
left: -35px;
bottom: 0px;
}
.messages--sent .message {
float: right;
max-width: 80%;
background-color: #1998e6;
color: #fff;
font-size: 12px;
border-bottom-right-radius: 15px;
border-top-right-radius: 15px;
}
.messages--sent .message:first-child {
border-top-right-radius: 50px;
}
.messages--sent .message:last-child {
border-bottom-right-radius: 50px;
margin-bottom: 10px;
}
我的问题是它在 ng-repeat 期间的每个循环都会创建一个新的 div,我不希望这样。为了实现该布局,如果它们的 {{message.id}} 都匹配,我想将下一个 {{message.content}} 附加到先前创建的 div 中。
否则,如果它们不匹配,只需像往常一样创建一个新的 div。 请帮忙谢谢:)
注意:我不想过滤它并将所有内容分组,我之前发布了一个问题但大多数人都误解了它所以我这次发布了一些照片以便更清楚地理解。谢谢 ^_^
【问题讨论】:
标签: javascript html css angularjs