如何利用mappingcontext.processAnonType [英] how to tap into mappingcontext.processAnonType

查看:68
本文介绍了如何利用mappingcontext.processAnonType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用breezejs从服务器上获取实体和非实体...对于非实体,我们希望弄乱返回的对象,特别是我们要设置其原型...在完成微风代码之后似乎最适合这样做的地方是在MappingContext的下面的函数中...在这里,我们可以访问结果,这是微风返回给客户端的对象,并且我们还可以访问的 $ type属性节点。有了这些信息,我们就可以通过解析$ type并用它更新结果来找到一个构造函数,这样结果看起来就像是找到的构造函数的一个实例...是否有任何拦截点可以帮助我?我的问题是,当对象通过微风移交时,我无权访问 node。$ type属性,该属性需要我才能找到构造函数...谢谢

we use breezejs to get both entities and non entities from the server... for the non entities we would like to mess with the returned objects, specifically we want to set their prototype... after stepping through the breeze code it seems like the perfect spot to do this would be in the function below of the MappingContext... here we have access to "result" which is the object breeze returns to the client and we also have access to the "$type" property of "node". With this information on hand we could find a constructor function by parsing $type and update result with it so that result will look like an instance of the constructor function found... are there any interception points that could help me? my problem is that when the objects are handed over by breeze, i don't have access to the "node.$type" property which i need in order to find the constructor function... thank you

function processAnonType(mc, node) {
        // node is guaranteed to be an object by this point, i.e. not a scalar          
        var keyFn = mc.metadataStore.namingConvention.serverPropertyNameToClient;
        var result = {};

        __objectForEach(node, function (key, value) {
            var newKey = keyFn(key);
            var nodeContext = { nodeType: "anonProp", propertyName: newKey };
            visitNode(value, mc, nodeContext, result, newKey);
        });
        return result;
    }


推荐答案

实际上,我认为您可以通过使用自定义 jsonResultsAdapter 来完成您需要的操作。请参阅: http://www.getbreezenow.com/documentation/jsonresultsadapters

Actually, I think you can do what you need by using a custom jsonResultsAdapter. See: http://www.getbreezenow.com/documentation/jsonresultsadapters

在visitNode方法中,您可以修改传入的节点对象或创建一个新对象(通过返回的哈希值上的 node属性)。如果该节点不是实体,则您返回的所有内容都会直接传递给客户端,而无需进行修改。

In the visitNode method you can either modify the incoming 'node' object or create a new one ( via a 'node' property on the returned hash). If the node is NOT an entity then whatever you return will be passed thru without modification to your client.

这篇关于如何利用mappingcontext.processAnonType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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