问题描述
我试图在页面上执行任何查询之前获取元数据,因为每个查询尝试获取总共5次元数据并且页面非常慢.我希望这会有所帮助.
I am trying to get the metadata before I perform any queries on the page, because each query is trying to get the metadata for a total of 5 times and the page is very slow. I am hoping this helps.
//版本信息:var breeze = {版本:"1.5.4",metadataVersion:"1.0.5"};
//version info:var breeze = { version: "1.5.4", metadataVersion: "1.0.5" };
但是我遇到此错误:
manager.fetchMetadata(...).then(...).fail不是函数
这是代码示例:
var manager = emProvider.createManager();
function getMetaData()
{
var deferred = $q.defer();
manager.fetchMetadata()
.then(function (data, status) {
deferred.resolve(data);
console.log('manager.fetchMetadata() success');
})
.fail(function (data, status) {
deferred.reject(data);
console.log('manager.fetchMetadata() reject');
});
return deferred.promise;
}
这就是注入的"emProvider"服务中的createManager函数的样子.
THis is what the createManager function looks like from the injected 'emProvider' service.
var masterManager = new breeze.EntityManager(serviceRoot + 'odata/');
// private function to create a new manager
function createManager() {
var manager = masterManager.createEmptyCopy(); // same configuration; no entities in cache.
// ... copy in some entities (e.g.,picklists) from masterManager
return manager;
}
推荐答案
如果您使用的是AngularJS中的 $ q
,则应使用 .catch
而不是.fail
. AngularJS使用.catch 来处理承诺中的错误.
If you are using $q
from AngularJS, you should use .catch
instead of .fail
. AngularJS uses .catch for errors in promises.
这篇关于BreezeJs在页面上加载了5次元数据,尝试使用fetchMetaData,但是它出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!