BreezeJs loading metadata 5 times on the page, trying to use fetchMetaData but it errors

…衆ロ難τιáo~ 提交于 2019-12-25 09:05:29

问题


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.

//version info: var breeze = { version: "1.5.4", metadataVersion: "1.0.5" };

Howevever I am getting this error:

manager.fetchMetadata(...).then(...).fail is not a function

Here is the code sample:

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

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

回答1:


try the following... surround all of your code blocks with anonymous self-invoking functions except for the master manager creation, comment out the getMetaData function, be sure to pick up the right adapter for your service... breeze odata configuration , make sure Q is on your js bundle at the top of your page.

breeze.config.initializeAdapterInstance("dataService", "odata");
var masterManager = new breeze.EntityManager(serviceRoot + 'odata/');

(function () {
    var op = breeze.FilterQueryOp;
    var query = null;
    query = new breeze.EntityQuery()...
    ...all of your other breeze code...
    masterManager.executeQuery(query).then(function (data) {...
})();



回答2:


If you are using $q from AngularJS, you should use .catch instead of .fail. AngularJS uses .catch for errors in promises.



来源:https://stackoverflow.com/questions/39068782/breezejs-loading-metadata-5-times-on-the-page-trying-to-use-fetchmetadata-but-i

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