Is the withParameters parameter still supported in a request to a Breeze?

I tried to use a method withParametersfor such a request:

query.withParameters({ includeLocation: true })

Unfortunately, my parameter has not been added to url. I use breeze.debug.js and I found this line in it

//queryOptions = __extend(queryOptions, this.parameters);

This is mistake? Is support allocated withParameters? Or am I doing something wrong?

I am using oData p>

+4
source share
2 answers

When used .withParameters, parameters are added to the URL by the data adapter, and not using the Breeze kernel. That is why this line is commented out. This allows you to encode parameters in different ways, depending on the backend used.

, OData, Breeze 1.4.8, .withParameters. WebApi, OData. . .

/ , - OData, . , OData ?

+2

, : https://github.com/Breeze/breeze.js/issues/19.

( , pull request):

var odataAdapter = breeze.config.getAdapterInstance('uriBuilder', 'OData');
var origBuildUri = odataAdapter.buildUri;
odataAdapter.buildUri = function (entityQuery, metadataStore) {
    var uri = origBuildUri(entityQuery, metadataStore);

    //Add custom query option support to webapi odata.
    //See https://github.com/Breeze/breeze.js/issues/19
    if (entityQuery.parameters !== null && typeof entityQuery.parameters === 'object'
        && Object.keys(entityQuery.parameters).length)
    {
        var queryParams = {};
        for (var param in entityQuery.parameters) {
            if (/^([^\$].*)$/.test(param)) {
                var val = entityQuery.parameters[param];
                if (typeof val == 'string') val = "'" + val + "'";
                queryParams[param] = val;
            }
        }

        //get the uri without the resourceName
        var resourceName = entityQuery.resourceName;
        uri = uri.substr(resourceName.length + 1);

        //build the new uri
        uri = resourceName + toQueryOptionsString(queryParams) + '&' + uri;
    }

    //Copied from breeze.js OData adapter
    function toQueryOptionsString(queryOptions) {
        var qoStrings = [];
        for (var qoName in queryOptions) {
            var qoValue = queryOptions[qoName];
            if (qoValue !== undefined) {
                if (qoValue instanceof Array) {
                    qoValue.forEach(function (qov) {
                        qoStrings.push(qoName + "=" + encodeURIComponent(qov));
                    });
                } else {
                    qoStrings.push(qoName + "=" + encodeURIComponent(qoValue));
                }
            }
        }

        if (qoStrings.length > 0) {
            return "?" + qoStrings.join("&");
        } else {
            return "";
        }
    }

    return uri;
};
0

Source: https://habr.com/ru/post/1527508/


All Articles