gpt4 book ai didi

javascript - AngularJs。使用 ng Repeat 和 ng switch 渲染表

转载 作者:行者123 更新时间:2023-12-02 18:05:52 26 4
gpt4 key购买 nike

我正在尝试使用 angularjs 指令渲染包含两列的表格。

<table>
<tr ng-repeat="message in messages" >
<td ng-switch-on="message.network" ng-switch when="twitter" ng-controller="TweetController">
<span>
<input type="checkbox" name="active" ng-checked="{{message.isPublished}}" data-id="{{message.socialId}}" ng-click="publishMessage($event)" />
</span>
<span>
<img src="{{message.authorPicture}}" />
</span>
<span>{{message.createdAt}}</span>
<span>{{message.network}}</span>
<span>{{message.text}}</span>
</td>
<td ng-switch-on="message.network" ng-switch when="facebook" ng-controller="FacebookController">
<span>
<input type="checkbox" name="active" ng-checked="{{message.isPublished}}" data-id="{{message.socialId}}" data-createdAt="{{message.createdAt}}" ng-click="publishMessage($event)" />
</span>
<span>
<img src="{{message.authorPicture}}" />
</span>
<span>{{message.createdAt}}</span>
<span>{{message.network}}</span>
<span>{{message.text}}</span>
</td>
</tr>
</table>

应该有两列 - 第一列应该是 Twitter 消息,第二列应该是 Facebook 帖子。但就我而言,相同的消息会在两列中呈现(像这样 http://puu.sh/5oHT7.png )。我做错了什么?

最佳答案

为了简单起见,只需重构模型即可:

$scope.messages = [
[
{
"network": "twitter",
...
},
{
"network": "facebook",
...
}
],
[
{
"network": "twitter",
...
},
{
"network": "facebook",
...
}
]
]

HTML:

<table>
<tr ng-repeat="message in messages" >
<td ng-repeat="msg in message">
<div ng-if="msg.network == 'twitter'">
<div ng-controller="TweetController">
...
<span>{{msg.createdAt}}</span>
<span>{{msg.network}}</span>
<span>{{msg.text}}</span>
</div>
</div>
<div ng-if="msg.network == 'facebook'">
<div ng-controller="FacebookController">
...
<span>{{msg.createdAt}}</span>
<span>{{msg.network}}</span>
<span>{{msg.text}}</span>
</div>
</div>
</td>
</tr>
</table>

关于javascript - AngularJs。使用 ng Repeat 和 ng switch 渲染表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20113253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com