1.不同scope之间的通信

(1)无父子关系的scope通信:

在需要操作的scope里面定义一个事件,名称为delete_host,参数为data

$rootScope.$on('delete_host', function(event,data) {
angular.forEach($scope.hosts, function (item, i) {
if (item.id == data) {
$scope.hosts[i].deleted = true;
}
if($scope.selected_host && $scope.selected_host.id == data){
$scope.selected_host = null;
} })
});

在需要触发该事件的scope里面触发

$rootScope.$emit('delete_host',$scope.selected_host.id);

注意为rootscope,emit

(2)父子关系下scope通信

<div  ng-controller="FatherCtrl">
<div ng-controller="ChildCtrl"> </div>
</div>

父scope里面写事件,传递参数为data

$scope.$on('change-breadcrumb', function(event,data) {
$scope.breadcrumb = Util.breadcrumb("h"+$routeParams.id,data);
});

子scope里面触发事件,注意为emit

$scope.$emit('change-breadcrumb',newValue)

子scope里面写事件,传递参数为data

$scope.$on('showdetail-storage', function(event,data) {
$scope.selected_storage = data ;
});

父scope里面触发事件,注意为broadcast

$scope.$broadcast('showdetail-storage',storage);

备注:父类向子类触发事件 用boradcast

子类向父类触发事件 用emit

2.定时任务

linux里面的cron可以实现定时任务。

crontab -e 编辑执行周期 以及执行方法
00 00 * * * python (路径)/license_day_count.py  每天00:00分执行该py文件
service crond stop 关闭服务 service crond start开启服务
/var/spool/mail/root 可查看部分信息

打开base64加密的文件,定时更新,并加密存入文件

daycountfile = open('/opt/filename"')
try:
daycountstr = daycountfile.read().strip()
daycount = int(base64.decodestring(daycountstr))
daycount = daycount - 1
file_writer = open('/opt/filename'', 'w')
file_writer.write(base64.encodestring(str(daycount)))
file_writer.close()
finally:
daycountfile.close()

3.代码冗余处理

从List<Entity>里面获取id的列表

storage_ids = [s.id for s in storages]
storage_names = [s.name for s in storages]

从LIst<JsonObj>里面获取某个属性的列表

alivenames = [s.get('storage') for s in result]

比较storage_names和alivenames ,如果后者缺少某个值,则进行某些操作

for storage in storages:
if storage.name not in alivenames:
result.append({"storage": storage.name, "name": "无"})

python , angular js 学习记录【2】的更多相关文章

  1. python , angular js 学习记录【1】

    1.日期格式化 Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 199 ...

  2. python , angular js 学习记录【3】

    1.Alembic是SQLAlchemy作者编写的Python数据库迁移工具.用它实现模型类和数据库的同步更新.(安装以及操作步骤 使用Alembic迁移数据库) 使用Alembic添加数据库字段操作 ...

  3. 适合我胃口的angular.js学习资料

    断断续续弄了半年的ANGULAR.JS学习资料,网上下载了N多资料,测试了很多次. 现在只能算是入门,因时间问题,现在要转入其它领域. 如果以后要拾起来,下面这个PDF比较对我胃口. <Angu ...

  4. 我的three.js学习记录(二)

    通过上一篇文章我的three.js学习记录(一)基本上是入门了three.js,但是这不够3D,这次我希望能把之前做的demo弄出来,然后通过例子来分析操作步骤. 1. 示例 上图是之前做的一个dem ...

  5. 我的three.js学习记录(三)

    此次的亮点不是three.js的3d部分,而是通过调用摄像头然后通过摄像头的图像变化进行简单的判断后进行一些操作.上篇中我通过简单的示例分析来学习three.js,这次是通过上一篇的一些代码来与摄像头 ...

  6. vue.js学习记录

    vue.js学习记录 文章已同步我的github笔记https://github.com/ymblog/blog,欢迎大家加star~~ vue实例 生命周期 beforeCreate:不能访问thi ...

  7. "利用python进行数据分析"学习记录01

    "利用python进行数据分析"学习记录 --day01 08/02 与书相关的资料在 http://github.com/wesm/pydata-book pandas 的2名字 ...

  8. D3.js学习记录【转】【新】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. angular.js学习的第一天

    第一天对angular.js进行学习,肯定是面对的入门的最简单的实例: 实现下面的这个效果,首先需要在html页面引入angular.js,在下面的div中,ng-app则表示在当前div是一个ang ...

随机推荐

  1. Struts2 contentType属性列表

    Struts2 contentType属性列表 博客分类: Struts 2   'ez' => 'application/andrew-inset', 'hqx' => 'applica ...

  2. StackExchange.Redis通用封装类分享(转)

    阅读目录 ConnectionMultiplexer 封装 RedisHelper 通用操作类封 String类型的封装 List类型的封装 Hash类型的封装 SortedSet 类型的封装 key ...

  3. JavaScript模板引擎artTemplate.js——template()方法

    template(id, data)方法: id:必传,渲染模板的id. data:可选,一个Object对象. return:传data—>渲染完成html代码:不传data—>一个渲染 ...

  4. iOS开发小技巧--iOS键盘 inputView 和 inputAccessoryView

    iOS键盘 inputView 和 inputAccessoryView 1.inputAccessoryView UITextFields和UITextViews有一个inputAccessoryV ...

  5. 【转】单调队列优化DP

    转自 : http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列是一种严格单调的队列,可以单调递增,也可以单调递减.队 ...

  6. Cocos2d-x 3.X 事件分发机制

    介绍 Cocos2d-X 3.X 引入了一种新的响应用户事件的机制. 涉及三个基本的方面: Event listeners 封装你的事件处理代码 Event dispatcher 向 listener ...

  7. css 拾遗

    1, 实现尖角 <style> .up{ border-top: 30px solid red; border-right:30px solid gold; border-bottom:3 ...

  8. Angular作用域的层级概念(scope)

    首先引入 angular 的根作用域:$rootScope ng-app:定义了angualr的作用域 ng-controller:定义了控制器 $scope定义了视图与控制器之间的纽带,而scope ...

  9. PHPstorm的数据库功能

    PHPstorm真是神器,居然有表.视图.存储过程的功能,非常人性化,建表那叫一个舒服,而且sql语句可以像其他代码一样显示"区域",结构更加清晰.

  10. 数据结构作业——hash(字符串哈希)

    Hash Description 给定长度为 n ( n<=1000000)的字符串,字符串仅由小写字母的前 m ( m<=6) 个字符组成,请你计算出共有多少长度为 k( k<=6 ...