Override a method in dojo - dojo.store.Memory

一笑奈何 提交于 2019-12-11 19:01:26

问题


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


回答1:


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...



来源:https://stackoverflow.com/questions/17552872/override-a-method-in-dojo-dojo-store-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!