来自服务的json电话迟到了吗?

时间:2016-01-11 15:28:32

标签: angularjs json asp.net-mvc-4

这是我的HTML,在点击时调用一个函数:

<span class="hover margin-right-10px pull-left" ng-click="**leadsactivity.addNote(item)**"
                              tooltip="Add Note"
                              tooltip-placement="left"
                              tooltip-trigger="mouseenter">
                            <i class="glyphicon glyphicon-book edit-font"></i>
                        </span>

这是在控制器中调用的函数:

leadsactivity.addNote = function (item) {
    var obj = {
        leadsactivity: leadsactivity,
        selectedItem: item,
        reuslt: null
    };

    leadsService.getActivityNote(item.id,function (data) {
        if (result) {
            obj.result = result;
        }
        _showNoteDialog(obj);
    });
};

表单会打开,但问题是该服务尚未发送响应数据,因此无法显示表单数据。

最后,这是服务:

_getActivityNote = function (id,callback) {
        resource.user.getActivity_noteById({ id: id })
          .$promise.then(function (response) {
              if (response.success) {
                  _leadsObject.activityNotes = response.data;
              }
              else
                  notifyService.notifyError("error");
          }, _errorCallback);


        return _leadsObject;
    }

JSON响应迟到,因此数据不会出现在表单中。可以采取哪些措施来解决这个时间问题?

1 个答案:

答案 0 :(得分:1)

控制器中的

校正:

leadsactivity.addNote = function (item) {
var obj = {
    leadsactivity: leadsactivity,
    selectedItem: item,
    reuslt: null
};
leadsService.getActivityNote(item.id,function (result) {
    if (result) {
        obj.result = result;
    }
    _showNoteDialog(obj);
});
};

服务更正:

_getActivityNote = function (id,callback) {
    resource.user.getActivity_noteById({ id: id })
      .$promise.then(function (response) {
          if (response.success) {
              _leadsObject.activityNotes = response.data; // what is the purpose of this ??
              callback(response.data);
          }
          else
              notifyService.notifyError("error");
      }, _errorCallback);
}

试试这个,让我知道(为什么)它没有工作