【问题标题】:resource query call execution timing资源查询调用执行时间
【发布时间】:2015-01-12 03:08:55
【问题描述】:

我的代码如下:

    // Find a list of Adverts
    $scope.find = function() {
        debugger;
        $scope.adverts = Adverts.query();
        doSomethingWithAdverts();
    };

其中$scope.find()data-ng-init="find()" 调用

当我通过函数进行调试时,当我跨过$scope.adverts = Adverts.query(); 行并将调试器保持在doSomethingWithAdverts(); 上时,我在firebug 中看不到HTTP GET 调用,只有当我恢复执行并退出此函数时.为什么会这样,我还以为Adverts.query();会启动ajax调用呢?

这会在尝试使用 doSomethingWithAdverts() 中的响应数据时导致不正确的行为

【问题讨论】:

    标签: javascript angularjs meanjs


    【解决方案1】:

    我找到了答案:

    在资源查询返回响应后需要执行的任何操作都放在回调函数中,如下所示:

        // Find a list of Adverts
        $scope.find = function() {
            debugger;
            $scope.adverts = Adverts.query(function(){
               doSomethingWithAdverts();
            });
    
        };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多