AngularJS将数据数组添加到$ http请求

时间:2022-02-06 03:30:07

I'm going to add some data in an array to $http service in angularjs. The way I add them to service is mentioned below (and it works properly)

我将在一个数组中添加一些数据到angularjs中的$ http服务。我将它们添加到服务的方式如下所述(并且它正常工作)

var inputValueArray  = new Array($scope.formdata);

I can get data by index zero in my api. But I want to get by named index. So, I do something like this:

我可以在api中通过索引零获取数据。但我希望通过命名索引。所以,我做这样的事情:

var inputValueArray  = new Array();
inputValueArray["myIndex"] = $scope.formData;

But, in api I get empty array. Then I did this solution:

但是,在api我得到空数组。然后我做了这个解决方案:

var inputValueArray = {"myIndex" : $scope.formData};

Now I get Maximum call stack size exceeded error. In both , I use $_POST to get data. I mean I'm sending data by $.param() like this :

现在我得到最大调用堆栈大小超出错误。在两者中,我使用$ _POST来获取数据。我的意思是我通过$ .param()发送数据,如下所示:

data: $.param({ mydata:inputValueArray , csrf_token: myTokenKey})

Any idea would highly appreciated.

任何想法都会高度赞赏。

1 个解决方案

#1


0  

According to ECMAScript 2015 (ES6) standard javascript has a Map implementation.

根据ECMAScript 2015(ES6)标准,javascript有一个Map实现。

link

Example:

var myMap = new Map();

var keyString = "a string",
    keyObj = {},
    keyFunc = function () {};

// setting the values
myMap.set(keyString, "value associated with 'a string'");
myMap.set(keyObj, "value associated with keyObj");
myMap.set(keyFunc, "value associated with keyFunc");

myMap.size; // 3

// getting the values
myMap.get(keyString);    // "value associated with 'a string'"
myMap.get(keyObj);       // "value associated with keyObj"
myMap.get(keyFunc);      // "value associated with keyFunc"

myMap.get("a string");   // "value associated with 'a string'"
                         // because keyString === 'a string'
myMap.get({});           // undefined, because keyObj !== {}
myMap.get(function() {}) // undefined, because keyFunc !== function () {}

#1


0  

According to ECMAScript 2015 (ES6) standard javascript has a Map implementation.

根据ECMAScript 2015(ES6)标准,javascript有一个Map实现。

link

Example:

var myMap = new Map();

var keyString = "a string",
    keyObj = {},
    keyFunc = function () {};

// setting the values
myMap.set(keyString, "value associated with 'a string'");
myMap.set(keyObj, "value associated with keyObj");
myMap.set(keyFunc, "value associated with keyFunc");

myMap.size; // 3

// getting the values
myMap.get(keyString);    // "value associated with 'a string'"
myMap.get(keyObj);       // "value associated with keyObj"
myMap.get(keyFunc);      // "value associated with keyFunc"

myMap.get("a string");   // "value associated with 'a string'"
                         // because keyString === 'a string'
myMap.get({});           // undefined, because keyObj !== {}
myMap.get(function() {}) // undefined, because keyFunc !== function () {}