如何扩展AngularJS资源(How to extend AngularJS resource)
要将json对象属性从String调整为Date以抑制AngularJS警告,请将datefmt错误调整为日期输入。 问题是:以下代码可以实现,但有点难看,是否有更美丽的实现?
'use strict'; var ahbHotelService = angular.module('ahbHotelService',['ngResource']); ahbHotelService.factory('Hotel',['$resource',function($resource){ var AHBHotel = $resource('/api/hotel/:id',{},{ query:{method:'GET',params:{id:''},isArray:true} }); var protoGet = AHBHotel.get; AHBHotel.get = function(params){ var result = protoGet(params); result.$promise.then(function(){ result.created = new Date(result.created); }); return result; }; return AHBHotel; }]);
To adjust json object property from String to Date to suppress an AngularJS warning, datefmt error for date input. The QUESTION is: the following code could implement, but somewhat ugly, is there more beautiful implementation?
'use strict'; var ahbHotelService = angular.module('ahbHotelService',['ngResource']); ahbHotelService.factory('Hotel',['$resource',function($resource){ var AHBHotel = $resource('/api/hotel/:id',{},{ query:{method:'GET',params:{id:''},isArray:true} }); var protoGet = AHBHotel.get; AHBHotel.get = function(params){ var result = protoGet(params); result.$promise.then(function(){ result.created = new Date(result.created); }); return result; }; return AHBHotel; }]);
原文:https://stackoverflow.com/questions/30291792
更新时间:2022-03-12 13:03
最满意答案
它应该工作,虽然它不是真正的解决方案:
import anydbm db = anydbm.open('cache2','c') db['www.python.org'] = 'python website' db['www.cnn.com'] = 'cable news network' for key in db.keys(): print key, db[key]
It should work although it is not the real solution:
import anydbm db = anydbm.open('cache2','c') db['www.python.org'] = 'python website' db['www.cnn.com'] = 'cable news network' for key in db.keys(): print key, db[key]
相关问答
更多-
为什么Module.method_defined?(:method)不能正常工作?(Why doesn't Module.method_defined?(:method) work correctly?)[2022-03-09]
要知道模块是否有模块方法,你可以使用respond_to? 在模块上: Something.respond_to?(another) => true method_defined? 会告诉你包含模块的类的INSTANCES是否响应给定的方法。 To know whether the module has a module method, you can use respond_to? on the module: Something.respond_to?(another) => true method ... -
由于没有抛出异常,我猜您错误地配置了您的SMTP服务器或根本没有。 如何做到这一点可以在这里阅读: http : //documentation.magnolia-cms.com/modules/mail.html#ConfiguringSMTP 另外,确保: 您的邮件没有登陆任何垃圾邮件过滤器(可能在您的邮箱之外) 没有阻塞防火墙(例如,在localhost上运行时) Ok, I finally solve it with this code: protected void sendEmail(Comme ...
-
谢谢大家的回答。 实际上这是我做的转储错误。 我不知道validate()方法是由save()调用的。 实际上我试图保存一个用户,我不明白为什么我的CustomUser模型中的规则没有运行 - _ - 。 测试是在我的用户:rules()和我的CustomUser :: rules()继承我的User :: rules()...无论如何我修复了这个问题。 如果(myCustomUser->验证()){ myUser =新用户; ...... myUser->保存(假); } 就像我可以用CustomUser ...
-
如果我正确地阅读你的问题,你假设==将比较两个对象的属性。 它没有,这就是equals 。 ==告诉您两个引用是否属于同一个对象实例,而不是相同的对象实例。 例如: public class Foo { public Foo(int x, int y) { this.x = x; this.y = y; } @override public boolean equals(Object other) { Foo otherFoo ...
-
您的属性可能未被默认加载。 如果没有解决向集合的addAttributeToSelect()语句添加height的根本问题,则可以重新加载产品模型: $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId()); echo $product->getHeight(); 尽管如此,这并没有解决问题的根源,并且引发了额外的数据库查询。 几个月前,我问了一个类似的问题,那就是加载包含更多信息的附加数据,虽然与单个 ...
-
发生了三件事。 (1)上述作业是否在正确的位置? uimap...xxxParams.yyyEdit = ...; 应该在调用使用它的方法之前。 (2)您可以使用Visual Studio调试器来设置断点并逐步执行Coded UI测试。 (您需要右键单击codeduitest.cs文件并选择Debug tests 。 (3)从澄清问题的评论中。 您需要同时进行分配和呼叫。 所以一般形式是uimap...xxxParams.yyyEdit = ...; uimap...xxx(); uimap...xxxPa ...
-
它应该工作,虽然它不是真正的解决方案: import anydbm db = anydbm.open('cache2','c') db['www.python.org'] = 'python website' db['www.cnn.com'] = 'cable news network' for key in db.keys(): print key, db[key] It should work although it is not the real solution: import any ...
-
我认为这取决于它选择使用哪种实现方式。 在我的系统上,Python 3中的dbm选择使用ndbm,这相当于Python 2中的dbm模块。当我明确使用该模块时,我看到了相同的限制。 看来Python 2中的anydbm选择dumbdbm,这个速度较慢,但确实支持完整的字典界面。 您可能希望在Python 2和3中查看shelve模块,它在这些接口上添加了另一层(允许您存储任何可pickle对象)。 I think this depends which implementation it chooses to ...
-
NSTimer不起作用(NSTimer doesn't work)[2021-10-16]
好的,我发现了问题的根源。 当Socket Rocket收到空间可用的通知时,它不会立即处理此通知,而是将通知发送到工作队列并在那里进行处理。 所以当- (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)len调用- (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)len方法时,当前事件循环与调度队列相关,而这个队列并不完全正常。 您无法为此类运行循环添加 ... -
更新方法签名时,必须更新被调用方法的每个实例以反映新参数。 在第65行的ProductController中,它仍然使用旧方法签名(包含item和id)。 要修复它,请更新控制器中的方法调用以使用$ id。 When you update the method signature you have to update every instance of that method being called to reflect the new parameters. In your ProductControl ...