LeanCloud with Angularjs tips (1)
来源:互联网 发布:json打印出来 编辑:程序博客网 时间:2024/04/29 22:30
由于Angularjs使用的是plain object,而LeanCloud用的是一个封装起来的对象,所以没法简单的在angular里使用{{xx.yy}}这样的方式来绑定数据。
官方给出了方法是这篇Blog所述,使用Object.defineProperty来解决。
Object.defineProperty(Todo.prototype, "title", { get: function() { return this.get("text"); }, set: function(aValue) { this.set("text", aValue); } });
这方法很好,所以我们可以直接写一个service来把它作为一个基础服务使用。
angular.module('demo') .service('leancloud', function leancloud() { var ClassDefines = { 'Product': {attributes: ['name', 'website']}, 'ProductDetail': {attributes: ['size', 'price']} }; return { angularizeAll: function () { angular.forEach(ClassDefines, function (classDefine, className) { var classObject = AV.Object.extend(className); angular.forEach(classDefine.attributes, function (attr) { Object.defineProperty(classObject.prototype, attr, { get: function () { return this.get(attr); }, set: function (value) { this.set(attr, value); } }); }) }) } } });
在程序的开始执行
angular.module('demo').run(function (leancloud) { leancloud.angularizeAll(); });
就可以尽情使用绑定带来的好处啦~
0 0
- LeanCloud with Angularjs tips (1)
- LeanCloud
- AngularJs integrate with Yii
- AngularJS with Cookies Example
- AngularJS with MVC4 CRUD
- Tips on working with Theano
- OWL Carousel integration with AngularJS
- Building Huuuuuge Apps with AngularJS
- Tutorial: Using AngularJS with Django
- Angularjs with Asp.net/core
- Tips For Working With Unity #4: Coding and General Tips
- 关于leancloud
- LeanCloud 调研
- 关于LeanCloud
- LeanCloud推送
- Tips for Scripting Java with Jython
- Handy Tips for Working with Excel 2003
- Getting started with JXTA - basic tips
- Kinect深度数据的处理
- 昆明门窗的选购技巧和要点
- laravel-路由篇-01
- 安装sql08命名实例后,服务器中找不到服务器的解决办法
- JDK框架简析--java.io包中的输入输出类库
- LeanCloud with Angularjs tips (1)
- cocos2dx中的文字显示
- map 几种遍历方法
- java 23种常用设计模式之桥接模式(Bridge)
- 作为码农, 如何快速掌握一门技术
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (
- 设置谷歌host地址
- Limbo- 简单访问远程数据库
- oracle插入多表(insert all/first)