Before using AngularJS I used this code to get JSON result of function

$.ajax({
        url: '@Url.Action("getGamedata", "Home")',
        type: 'GET',
        dataType: 'json',
        cache: false,
        async: false,
        success: function (gameInfo) {
            //alert(gameInfo.Name); //Working OK
            for(var i=0;i<6;i++)
                createTable(gameInfo[i]);
        }
    });

JSON result contain 6 items with name, genre, imageUrl and etc. Now I'm using AngularJS and I have function to build dynamic grid

function buildGridModel(tileTmpl) {
          var it, results = [];

          for (var j = 0; j < 6; j++) {

              it = angular.extend({}, tileTmpl);
              it.icon = it.icon + (j + 1);
              it.title = it.title + (j + 1);
              it.span = { row: 1, col: 1 };

              switch (j + 1) {
                  case 1:
                      it.background = "red";
                      break;

                  case 2: it.background = "green"; break;
                  case 3: it.background = "darkBlue"; break;
                  case 4:
                      it.background = "blue";
                      break;

                  case 5:
                      it.background = "yellow";
                      break;

                  case 6: it.background = "pink"; break;
              }

              results.push(it);
          }

          return results;
      }

I want to push each item title to my grid tile title.

  1. 1st tile title = 1st JSON item title
  2. 2nd tile title = 2nd JSON item title
  3. and etc
share|improve this question
    
can u post the code you have tried so far to do that ? – Umair Farooq Aug 31 '16 at 13:06

my solution: put ajax into function

function buildGridModel(tileTmpl) {
          var it, results = [];
          $.ajax({
              url: '/home/getGamedata',
              type: 'GET',
              dataType: 'json',
              cache: false,
              async: false,
              success: function (gameInfo) {

                  for (var j = 0; j < 6; j++) {

                      it = angular.extend({}, tileTmpl);
                      it.icon = it.icon + (j + 1);
                      it.title = gameInfo[j]["Name"];
                      it.span = { row: 1, col: 1 };

                      switch (j + 1) {
                          case 1:
                              it.background = "red";
                              break;

                          case 2: it.background = "green"; break;
                          case 3: it.background = "darkBlue"; break;
                          case 4:
                              it.background = "blue";
                              break;

                          case 5:
                              it.background = "yellow";
                              break;

                          case 6: it.background = "pink"; break;
                          case 7: it.background = "darkBlue"; break;
                          case 8: it.background = "purple"; break;
                          case 9: it.background = "deepBlue"; break;
                          case 10: it.background = "lightPurple"; break;
                          case 11: it.background = "yellow"; break;
                      }

                      results.push(it);
                  }
              }
          });

          return results;
      }
share|improve this answer
    
Nothing in your question or answer shows anything related to AngularJS. Check out the $http service in the Angular docs docs.angularjs.org/api/ng/service/$http – Matt M Aug 31 '16 at 14:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.