首页 \ 问答 \ 如何扩展AngularJS资源(How to extend AngularJS resource)

如何扩展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]

相关问答

更多
  • 要知道模块是否有模块方法,你可以使用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 ...
  • 好的,我发现了问题的根源。 当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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。