gpt4 book ai didi

javascript - 数据未显示在 ionic 和 Angular 列表中

转载 作者:行者123 更新时间:2023-11-30 00:11:17 29 4
gpt4 key购买 nike

我是 ionic 和 angular 的新手。试图用 json 数据创建一个列表

{"menu":[{"name":"Mixed Veg Wrap","image":"mix-veg-wrap.jpg","category":"WRAPS, Light Bites","spice_meter":"1","description":"Spicy mixed vegetables :)","rating":"3","price":"35","is_veg":"yes"},{"name":"Egg Wrap","image":"egg-wraps.jpg","category":"WRAPS, Light Bites","spice_meter":"0","description":"Double egg coating with Onion and Sauces!","rating":"4.9","price":"36","is_veg":"no"},{"name":"Cheese Melt Paneer","image":"cmp.jpg","category":"WRAPS, Special","spice_meter":"0","description":"Paneer in Reshmi Masala with melted Cheese","rating":"4.5","price":"91","is_veg":"yes"},{"name":"Prawns Tikka","image":"prawan.jpg","category":"WRAPS, Special","spice_meter":"1","description":"Prawns in spicy tikka masala.","rating":"3.5","price":"110","is_veg":"no"}

这是我的 Controller app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
}).controller('ListController', ['$scope', '$http', function($scope, $http) {
$http.get('js/data.json').success(function(data) {
$scope.menu = data;
});
}]);

这是我的 index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-dark">
<h2 class="title">Artist List</h2>
</ion-header-bar>
<div class="bar bar-subheader
item-input-inset bar-light">
<label class="item-input-wrapper">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" placeholder="Search">
</label>
</div>
<ion-content ng-controller="ListController"
class="has-subheader">
<ion-list>
<ion-item ng-repeat='item in menu'
class="item-text-wrap">
<h2>{{item.name}}</h2>
<img ng-src="img/{{item.image}}" />
<h3>{{item.category}}</h3>
<h3>{{item.spice_meter}}</h3>
<h3>{{item.description}}</h3>
<h3>{{item.rating}}</h3>
<h3>{{item.price}}</h3>
<h3>{{item.is_veg}}</h3>
</ion-item>
</ion-list>
</ion-content>
</ion-pane>
</body>
</html>

Nut 结果 o/p 是空白列表我检查了显示的控制台

ionic.bundle.js:17752 XHR finished loading: GET "http://192.168.1.201:8100/js/data.json".(anonymous function) @ ionic.bundle.js:17752sendReq @ ionic.bundle.js:17553serverRequest @ ionic.bundle.js:17269processQueue @ ionic.bundle.js:21114(anonymous function) @ ionic.bundle.js:21130Scope.$eval @ ionic.bundle.js:22326Scope.$digest @ ionic.bundle.js:22142Scope.$apply @ ionic.bundle.js:22431bootstrapApply @ ionic.bundle.js:9373invoke @ ionic.bundle.js:12110doBootstrap @ ionic.bundle.js:9371bootstrap @ ionic.bundle.js:9391angularInit @ ionic.bundle.js:9285(anonymous function) @ ionic.bundle.js:34050trigger @ ionic.bundle.js:10669eventHandler @ ionic.bundle.js:10939

请帮忙!!

最佳答案

确保您在浏览器控制台中看到的路径 http://192.168.1.201:8100/js/data.json 是正确的。

然后在分配菜单时使用 data.menu 而不仅仅是 data

.controller('ListController', ['$scope', '$http', function($scope, $http) {
$http.get('js/data.json').success(function(data) {
$scope.menu = data.menu; //assigning menu
});
}]);

关于javascript - 数据未显示在 ionic 和 Angular 列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36388335/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com