Angularjs中的JSON数据比较

时间:2017-04-08 18:37:29

标签: angularjs

我正在做一个大学项目。在类别页面中,将有来自json的产品类别 -

1.2.3.4,

由于类别列表对于例如4是动态的,因此尝试构建到列表页面的链接取决于基于JSON中的代码数据的类别。例如,如果在category.html中点击手机,那么result.html将是移动列表,如果iPad则是iPad列表。现在完成类别页面并尝试传递和接收JSON中的代码,以便在条件下进行比较,以显示笔记本电脑或台式机等相关数据。

现在的js是:

[{
        "code": "mc",
        "name": "Mobile",
        "desc": "We provide range of latest mobile phones with best price in the market",
        "imageUrl": "images/mobile.jpg"

    },
    {
        "code": "lc",
        "name": "Laptops",
        "desc": "Huge sale is going on Lenova,HP and Apple's laptop",
        "imageUrl": "images/lappy.jpg"

    },
    {
        "code": "ic",
        "name": "ipads",
        "desc": "ipad mini is available with the cheapest price.Go grab the offer",
        "imageUrl": "images/ipad.jpg"

    },
    {
        "code": "sc",
        "name": "Storage Devices",
        "desc": "All kind of storage devices are available here",
        "imageUrl": "images/storage.jpg"

    }
]

在result.html上显示 -

      var catApp = angular.module("catApp", ["ngStorage"]);
      catApp.controller('CountryCtrl', function ($scope, $http, $localStorage){
        $http.get('categories.json').success(function(data) {
          $scope.categories = data;
        });
 $scope.save = function() {
      window.location.replace('result.html');
      $scope.type=categories;
               if(type.code=='mc'){
                    localStorage.setItem('msg1', 'Mobiles');
                }
                $scope.data1 = localStorage.getItem('msg1');
      });

请帮我在result.html中显示产品名称,比较json中的'code'。 总之,想在result.html中显示类别名称取决于哪个类别用户点击哪个类别也来自json的动态来自fag值代码,以使其像 -

freshtechsample.tk/pal/test.html

唯一区别在于上面的html链接是静态的,在必需的页面链接中是动态的。

现在输出:http://freshtechsample.tk/pal/category.html

0 个答案:

没有答案