【发布时间】:2016-05-10 10:18:59
【问题描述】:
我有一个带有 angular 的 ionic 应用程序和一个我想显示的 json 文件。
这是我的 www 文件夹中的内容:
--css
--img
--js
----app.js
----controller.js
--lib
--map
----dep.json
--vendors
index.html
这是我的 index.html
的仿制品<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controller.js"></script>
<!-- svg map stuff -->
<link href="vendors/map/jqvmap.css" media="screen" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="vendors/map/jquery.vmap.js" type="text/javascript"></script>
<script src="vendors/map/jquery.vmap.france.js" type="text/javascript"></script>
[...]
<script id="templates/map.html" type="text/ng-template">
<ion-view view-title="Map">
<ion-content class="padding">
<div class="bar bar-header item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input type="search" placeholder="Recherchez une ville, un code postal" ng-model="query">
</label>
<button class="button button-clear">
Cancel
</button>
</div>
<div ng-controller="CustomerController">
<div id="francemap"style="width: 500px; height: 500px;"></div>
<button type="button" ng-click="myName('Mowso')"> Click Me :) </button>
</div>
<div class="list-dep" ng-controller="DepListCtrl">
<!--Body content-->
<ul class="deps">
<li ng-repeat="dep in deps | filter:query">
<p>{{dep.code}} - {{dep.name}}</p>
</li>
</ul>
</div>
</ion-content>
</ion-view>
</script>
如您所见,它是一个带有标签的应用程序。起初我将数据放在 controller.js 中,但现在我希望将它们放在 json 文件中,但它们不再出现在屏幕上。我的 controller.js 看起来像这样:
'use strict';
/* Controllers */
var map = angular.module('ionicApp');
/*map.controller('DepListCtrl', function($scope) {
$scope.deps = [
{'code': '01', 'name': 'Ain'},
{...},
{'code': '974', 'name': 'Réunion'}
];
});*/
map.controller('DepListCtrl', ['$scope', '$http', function($scope, $http) {
$http.get('map/deps.json').success(function(data) {
$scope.dep = data;
console.log(data);
});
}]);
我拥有的所有数据都在我的 json 文件中(我在控制器中对它们进行了注释以跟踪我之前所做的事情,基本上它们在 json 中是相同的,但缩进更多)。
我昨天更新了我的 nodejs,但当我看到数据消失时,我切换回 v4-4-4。我没有任何控制台错误(我曾经有一个错误,因为我没有将我的 json 放在我的地图文件夹中,我很傻)并且我的控制器中的 console.log(data) 显示了一个数组和我所有的部门。
我做错了什么?
【问题讨论】:
-
您是否检查过它尝试在网络日志中查找的路径?
-
@Coss 不,我没有,现在已经解决了,但下次我会这样做,谢谢!
标签: javascript angularjs json ionic-framework