本文介绍了清风1.4.8和放大器;角阿贾克斯适配器:如何自定义AJAX设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code:

breeze.config.initializeAdapterInstance("ajax", "angular", true);

...

var ajaxAdapter = breeze.config.getAdapterInstance('ajax');

ajaxAdapter.defaultSettings = {
    method: 'POST',
    data: {
        CompanyName: 'Hilo Hattie',
        ContactName: 'Donald',
        City: 'Duck',
        Country: 'USA',
        Phone: '808-234-5678'
    }
};

在breeze.debug.js的14813行:

in line 14813 of breeze.debug.js:

ngConfig = core.extend(compositeConfig, ngConfig);

compositeConfig.method拥有,直到它被覆盖的POST的值,因为ngConfig.method有GET的值。

compositeConfig.method has a value of 'POST' until it is overwritten, because ngConfig.method has a value of 'GET'.

我想这个问题是相关的任何阿贾克斯设置,当然,我主要是冥思苦想着如何与后角阿贾克斯适配器,也许有一个完全更好的方式来做到这一点?这种方法感觉很脏,无论如何,但breeze.ajaxPost.js只能与jQuery的AJAX接口,对吧?

I imagine this question is relevant for any ajax setting, but of course I'm mainly struggling with how to post with the angular ajax adapter, so maybe there's an entirely better way to do that? this approach feels dirty anyway, but breeze.ajaxPost.js only works with the jQuery ajax adapter, right?

推荐答案

最近,我们有理由重新审视的 ajaxpost 的,并更新了两者的和的文档

6 Oct 2014 update

We recently had reason to revisit ajaxpost and have updated both the code and the documentation.

原来建议的工作。我们只是澄清和更新的幸福路径。

The original recommendation works. We're merely clarifying and updating the happy path.

的几点:

  • ajaxpost 的插件工程为jQuery和角阿贾克斯适配器。

  • The ajaxpost plug-in works for both jQuery and Angular ajax adapters.

这些适配器很久以前就意识到 adapter.defaultSettings.headers ,并已融合成你的微风的 ajaxpost 的HTTP调用(取谨慎,PW KAD)。

Those adapters long ago became aware of adapter.defaultSettings.headers and have blended them into your Breeze ajaxpost http calls (take heed, PW Kad).

您必须调用 breeze.ajaxPost()明确替换默认AJAX适配器,当您使用breeze.angular服务为你做之后。

You must call breeze.ajaxPost() explicitly after replacing the default ajax adapter as you do when you use the 'breeze.angular' service.

您可以明确地包裹某个特定的ajax适配器: breeze.ajaxPost(myAjaxAdapter); 我们只是不这样做,我们自己,因为,在我们的经验,足以省略PARAMS( breeze.ajaxPost()),并让该方法查找和包装无论是当下的积极AJAX适配器。

You can wrap a particular ajax adapter explicitly: breeze.ajaxPost(myAjaxAdapter); We just don't do that ourselves because, in our experience, it is sufficient to omit the params (breeze.ajaxPost()) and let the method find-and-wrap whatever is the active ajax adapter of the moment.

本文档介绍了角的用例,我在这里重复的话,你一定的时间:

The documentation explains the Angular use case which I repeat here to spare you some time:

// app module definition
var app = angular.module('app', ['breeze.angular']);  // add other dependencies

// this data service abstraction definition function injects the 'breeze.angular' service
// which configures breeze for angular use including choosing $http as the ajax adapter
app.factory('datacontext', ['breeze', function (breeze) {    // probably inject other stuff too
    breeze.ajaxPost(); // wraps the now-current $http adapter
    //... your service logic
}]);

的原答复

啊哈!感谢您的plunker(和巧妙地利用了藤堂棱角样品的复位方法!)。

Original reply

AHA! Thanks for the plunker (and the clever use of the Todo-Angular sample's reset method!).

在简短,实际的问题是, breeze.ajaxpost.js 的延伸jQuery的AJAX适配器,而不是角AJAX适配器。有计时问题

In brief, the actual problem is that breeze.ajaxpost.js extends the jQuery ajax adapter, not the angular ajax adapter. There is a timing problem.

的根本原因是,你不能告诉的 breeze.ajaxpost.js 的包装它的适配器。它总是包装在它运行的时候默认的适配器。当你有你的脚本的加载,jQuery的适配器是当前时的 breeze.ajaxpost.js 的运行。

The root cause is that you can't tell breeze.ajaxpost.js which adapter to wrap. It always wraps the default adapter at the time that it runs. As you've got your script loading now, the jQuery adapter is the current one when breeze.ajaxpost.js runs.

解决方法是之前默认的适配器设置为角度适配器的 breeze.ajaxpost.js 的运行。

The workaround is to set the default adapter to the angular adapter before breeze.ajaxpost.js runs.

要做到这一点的方法之一是加载脚本如下...添加内嵌脚本默认AJAX适配器设置为角的版本。

One way to do that is to load the scripts as follows ... adding an inline script to set the default ajax adapter to the "angular" version.


  <script src="breeze.debug.js"></script>
  <script>
        <!-- Establish that we will use the angular ajax adapter BEFORE breeze.ajaxpost.js wraps it! -->
        breeze.config.initializeAdapterInstance("ajax", "angular", true);
  </script>
  <script src="breeze.ajaxpost.js"></script>

显然,这是一个黑客。我们将看看我们如何能够改变的 breeze.ajaxpost.js 的,因此您可以在您方便的时间包装任何AJAX适配器。

Clearly this is a hack. We'll look into how we can change breeze.ajaxpost.js so you can wrap any ajax adapter at the time of your convenience.

这篇关于清风1.4.8和放大器;角阿贾克斯适配器:如何自定义AJAX设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:16