javascript - Treat all variables from HTTP request as as integer (with exception) -


I have an HTTP request in angular, which pulls all the data from a MySQL table.

  $ Http ({method: "POST", url: "framework / actions / league.php? Query = getDivision"}). Success (Tasks (Data) {$ scope.division = data;});  

A snippet of data looks like this:

  [{name: "any", number: "4", game 1: "6" Score: "10"}, Game 2: "2", Score: "8"}, {name: "any other", number: "7", game1: "7", game 2: "3" ]  

When that data comes back from HTTP request and is assigned to $ scope.division , the numbers are considered as strings, from which I get problems using orderBy ngRepeat in .

How can I count the numbers in the field without declaring each region in the forEach and use parseInt () ? Is it possible to do this in PHP? If it is not, then it would be OK to do it in Coonari Javascript.

Of course I can not think of each field as a number due to the name field.

You can either PHP function intval () to convert strings:

  $ string = '123'; $ Number = interval ($ string); // 123 $ num2 = interval ('456'); // 456  

or Casting directly to the Assignment statement :

  $ string = '123'; $ Number = ($ string); // 123 $ num2 = (int) '456'; Use the method to / / 456  

or in AngularJS :

  $ http ({method: "POST", URL: "framework / action / league.fp? Quieri = gate division", transport response: function (data for {var i = 0; i & lt; data; lang; i ++) if (data [i ] .hasOwnProperty (k)} {data [i] [k] = isNaN (+ data [i] [k]) data [i] [k]: + data [i] [k];}}} return data; }, Success: function (data) {$ scope.division = data;}});  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -