【问题标题】:Json array details show in three pages in angularjs with ionicJson 数组详细信息显示在 angularjs 的三个页面中,带有 ionic
【发布时间】:2016-09-03 14:39:56
【问题描述】:

我有类别数组。还有更多的产品。 我需要在类别页面中显示类别。 当点击一个类别时,我必须重定向产品页面并显示必要的产品。 单击产品时,我必须重定向 product_details 页面并显示必要的产品详细信息。

分类加载到分类页面,点击它会重定向产品页面。但是,我看不到产品。 以及这些控制器的错误是什么,以及如何创建“product_details.html”和“product.html”页面。

我必须这样展示:

  • 类别页面:term_id、名称
  • 产品页面:post_title、ID
  • 产品详情页面:post_title、post_date、post_author、ID

categorylist-product.json

{
"category": [{
    "term_id": "10",
    "name": "Arden Grange",
    "slug": "arden-grange",
    "products": [{
        "ID": "47",
        "post_title": "Arden Grange, Premium",
        "post_date": "2015-10-20 16:13:04",
        "post_author": "5"
    }, {
        "ID": "50",
        "post_title": "Arden Grange Puppy\/Junior Large Breed",
        "post_date": "2015-10-21 04:56:23",
        "post_author": "5"
    }, {
        "ID": "53",
        "post_title": "Arden Grange Weaning\/Puppy",
        "post_date": "2015-10-22 12:52:35",
        "post_author": "5"
    }]
}, {
    "term_id": "8",
    "name": "Menu 1",
    "slug": "menu-1",
    "products": [{
        "ID": "38",
        "post_title": "Home",
        "post_date": "2015-10-20 10:43:44",
        "post_author": "1"
    }, {
        "ID": "30",
        "post_title": "",
        "post_date": "2015-10-20 10:13:56",
        "post_author": "1"
    }, {
        "ID": "31",
        "post_title": "",
        "post_date": "2015-10-20 10:13:57",
        "post_author": "1"
    }]
}]
}

CategoryController.js

app.controller('CategoryController', ['$scope','category', function($scope, category) {

 category.success(function(data) {
     $scope.userslists = data;
});

}]);

ProductController.js

app.controller('ProductController', ['$scope', '$routeParams', 'category', function($scope, $routeParams, category,products) {

category.success(function(data) {
$scope.users = data.category[$routeParams.id];

});
}]);

app.js

var app = angular.module('LookApp', ['ionic','ngCordova','ngRoute']);

app.config(function($stateProvider, $urlRouterProvider,$routeProvider) {
$routeProvider

.when('/', {
controller: 'CategoryController',
templateUrl: 'views/category.html'
})

.when('/:id', {
controller: 'ProductController',
templateUrl: 'views/users.html'
})
 .when('/login/:friendId', {
controller: 'LoginController',
templateUrl: 'views/login.html'
})

.otherwise({
redirectTo: '/'

});

category.js(服务文件)

app.factory('category', ['$http', function($http) {    

return $http.get('http://localhost/youtubewebservice/shop-categorylist-product.php')


       .success(function(data) { 
          return data; 
        }) 
        .error(function(err) { 
          return err; 
        }); 
}]);

【问题讨论】:

  • 你需要把userslists放到分类、产品和详情页
  • 我必须像这样放置数据:“类别页面:term_id,名称”。 “产品页面:post_title,ID”。 " 产品详情页 : post_title, post_date, post_author, ID "
  • 您想在其他页面中显示所有数据还是仅显示特定 term_id 的详细信息??
  • 只有特定 term_id 的详细信息我的朋友。

标签: javascript jquery angularjs json ionic-framework


【解决方案1】:

看到您已将数据放在 $scope.userlists 中,因此当您在 html 中调用数据时,您需要这样做
类别页面

<div ng-repeat="user in userslists">
Term ID : {{user.category.term_id}}
Name    : {{user.category.name}}
</div>

产品页面

<div ng-repeat="user in userslists">
Post Title : {{user.category.products.post_title}}
ID         : {{user.category.products.ID}}
</div>

详情页

<div ng-repeat="user in userslists">
Post Title : {{user.category.products.post_title}}
Post Date  : {{user.category.products.post_date}}
Post Author: {{user.category.products.post_author}}
ID         : {{user.category.products.ID}}
</div>

【讨论】:

  • 我的朋友这个代码没用。如何更改控制器。
  • 您是否在 $scope.userslists 中的 controllers.js 中获取任何数据?你得到的json数据在localhost/youtubewebservice/shop-categorylist-product.php
  • stackoverflow.com/questions/37103142/…... 你能回答这个问题吗?这是我的全部问题,我的朋友。
  • 我使用 category.js(服务文件)从 mysql DB 获取这些数据。类别将加载到类别页面。点击分类后,也会进入商品页面,但无法加载商品。
猜你喜欢
  • 2016-10-07
  • 2020-11-29
  • 1970-01-01
  • 2020-01-20
  • 1970-01-01
  • 1970-01-01
  • 2021-01-09
  • 1970-01-01
  • 2020-11-01
相关资源
最近更新 更多