how to tap into mappingcontext.processAnonType

孤街醉人 提交于 2019-12-13 07:35:36

问题


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;
    }

回答1:


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

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.



来源:https://stackoverflow.com/questions/29243183/how-to-tap-into-mappingcontext-processanontype

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