覆盖dojo中的方法 - dojo.store.Memory [英] Override a method in dojo - dojo.store.Memory

查看:126
本文介绍了覆盖dojo中的方法 - dojo.store.Memory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



具体来说,我需要在查询之前刷新dojo.store.Memory中的数据(< )函数产生。我的想法是放置一个回调(将在query()之前产生),从服务器获取新数据,然后将数据设置为内存实例。然后只需调用

  this.inherited(arguments)

我已经尝试使用声明重写查询方法,但我仍然收到一些不相关的错误。 4小时但没有运气...



有另一种方式吗?



谢谢

解决方案

是的,您可以在任何方法之前,之后或之后触发回调。只需使用 dojo / aspect



这样的东西应该可以工作:

  require([dojo / store / Memory,dojo / aspect ],function(Memory,aspect){
aspect.before(Memory,query,function(){
// do something
});
});

但是,对于您的具体用例,如果我理解正确,您想要的是拥有一个商店链接到服务器端控制器。在这种情况下,您应该使用 dojo / store / JsonRest 比dojo / store / Memory。在查询之前不需要触发任何方法...


Is there a way how to run my own function before a dojo method is spawned?

Specifically I need to refresh data in dojo.store.Memory before query() function is spawned. My idea is to put there a callback (that will be spawned before query()), fetch new data from server and then set the data to Memory instance. Then just call

this.inherited(arguments)

I've tried override query method with declare, but I'm still getting some unrelated errors. 4 hours but no luck...

Is there a another way?

Thanks

解决方案

Yes, you can fire callbacks before, after or around any method. Just use dojo/aspect

Something like this should work :

require(["dojo/store/Memory", "dojo/aspect"], function(Memory, aspect){
    aspect.before(Memory, "query", function(){
        // do something
    });
});

However, for your specific use case, if I understood correctly, what you want is to have a store linked to a server-side controller. In that case, you should use dojo/store/JsonRest rather than dojo/store/Memory. No need to fire any methods before the query...

这篇关于覆盖dojo中的方法 - dojo.store.Memory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆