创建一个新的实体,当breezejs获取元数据 [英] breezejs fetching metadata when creating a new Entity

查看:111
本文介绍了创建一个新的实体,当breezejs获取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我拨打以下code:

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.

所以我的问题是,万一metadataStore没有一个类型的知识,我怎么能强制往返到服务器以获取元数据,对于这种类型的?什么是我的code最好的地方这样做?

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 ?

推荐答案

您可以调用的 manager.fetchMetadata 的然后执行您的 createEntity 的承诺解决之后调用。

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

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

您不必这样做,如果你第一次执行查询,因为查询执行隐式做了fetchMetadata如果它不能执行查询之前发现的元数据。所以下面将正常工作。

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");
    ...
 });

这篇关于创建一个新的实体,当breezejs获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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