breezejs fetching metadata when creating a new Entity

放肆的年华 提交于 2019-12-13 02:54:38

问题


When I call the following code:

function createMandat (initialValues) {
        return manager.createEntity('Mandate');
}

It fails because the type 'Mandate' is unknown. That I understand because I haven't yet fetched any entities of that type when I call this function.

So my question is, in case the metadataStore has no knowledge of a type, how can I force a round-trip to the server in order to get metadata for this type ? What is the best place in my code for doing so ?


回答1:


You can call manager.fetchMetadata and then perform your createEntity call after promise resolution.

 manager.fetchMetadata().then(function() {
    var newMandate = manager.createEntity("Mandate");
    ...
 });

You do not need to do this if you perform a query first, because query execution implicitly does a fetchMetadata if it can't find the metadata before executing the query. So the following will work as well.

manager.executeQuery(myQuery).then(function(data) {
    results = data.results;
    var newMandate = manager.createEntity("Mandate");
    ...
 });


来源:https://stackoverflow.com/questions/16143900/breezejs-fetching-metadata-when-creating-a-new-entity

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