问题
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