小编Rod*_*igo的帖子

在角度2中动态切换用户操作的html模板

使用Angularjs 1.x,您可以轻松地在编辑/读取模式之间的按钮单击上切换html模板.ng-include指令是关键.

<table>
    <thead>
        <th>Name</th>
        <th>Age</th>
        <th></th>
    </thead>
    <tbody>
        <tr ng-repeat="contact in model.contacts" ng-include="getTemplate(contact)">
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

get getTemplate函数执行以下代码:

$scope.getTemplate = function (contact) {
    if (contact.id === $scope.model.selected.id) return 'edit';
    else return 'display';
};
Run Code Online (Sandbox Code Playgroud)

这再次导致其中一个模板在UI中处于活动状态:

显示

  <script type="text/ng-template" id="display">
        <td>{{contact.name}}</td>
        <td>{{contact.age}}</td>
        <td>
            <button ng-click="editContact(contact)">Edit</button>
        </td>
    </script>
Run Code Online (Sandbox Code Playgroud)

编辑

<script type="text/ng-template" id="edit">
    <td><input type="text" ng-model="model.selected.name" /></td>
    <td><input type="text" ng-model="model.selected.age" /></td>
    <td>
        <button ng-click="saveContact($index)">Save</button>
        <button ng-click="reset()">Cancel</button>
    </td>
</script>
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/benfosterdev/UWLFJ/

对于Angular 2 RC 4,不存在n-include.

如何使用Angular 2 RC4进行相同的功能?

angular2-template angular

12
推荐指数
1
解决办法
1万
查看次数

如何在R中每月拆分数据

我有一个与商店购买记录相对应的数据集,它是这样的:

Date          BuyId      Price     Description    Category
2010-01-01    101028        100    ...            ...
2010-01-01    101028        100    ...            ...
2010-01-01    101028        100    ...            ...
2010-01-01    101028        100    ...            ...
...
Run Code Online (Sandbox Code Playgroud)

数据框中的日期从 2010-01-10 到 2015-04-01,我想每月拆分它,以便我可以绘制每年每月的购买量,我的意思是:

Date        Count
2010-Jan    19128
2010-Feb    1232
...
...
2015-Mar    28363
2015-Apr    12834
Run Code Online (Sandbox Code Playgroud)

我一直在为此感到困难,因为我对 R 很陌生,而且我不知道这么多功能。

我试图使用拆分数据,split但我无法做到。有谁知道我该怎么做?

split r dataset

2
推荐指数
1
解决办法
1854
查看次数

标签 统计

angular ×1

angular2-template ×1

dataset ×1

r ×1

split ×1