AngularJs.使用ng重复和ng开关渲染表



我正在尝试使用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>

应该有两列——第一列应该是推特消息,第二列应该是脸书帖子。但在我的情况下,相同的消息在两列中呈现(如下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>

相关内容

  • 没有找到相关文章

最新更新