【发布时间】:2015-02-19 10:42:33
【问题描述】:
我是 angularjs 新手,由于某种原因,当 json 来自 joomla 组件时,angularjs 不会在页面上加载任何数据。
当我从站点根目录中的 getcustomers.php 文件中获取数据时,Angularjs 可以工作,但当 json 数据来自 joomla 组件时,Angularjs 不会。 (http://localhost/testsite/index.php?option=com_helloworld&view=helloworld&format=raw)。
我可以看到 json 正在加载(确实为 getcustomers.php 和 joomla 组件直接点击了 url 也可以在页面加载时在 chrome 开发人员工具中看到)。
我可以看到两个 json 响应的唯一区别是双括号 [{"Id":87,"EANHotelID": }](工作 Json 示例),而不工作的 json 示例是 [[{"Id":87,"EANHotelID":}]]。
Angularjs 控制器如下:(工作和不工作的唯一区别是下面的 HTTP.GET:
var app = angular.module('myApp', ['ui.bootstrap']);
app.filter('startFrom', function() {
return function(input, start) {
if(input) {
start = +start; //parse to int
return input.slice(start);
}
return [];
}
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
$http.get('testsite/index.php?option=com_helloworld&view=helloworld&format=raw').success(function(data){
$scope.list = data;
$scope.currentPage = 1; //current page
$scope.entryLimit = 10; //max no of items to display in a page
$scope.filteredItems = $scope.list.length; //Initially for no filter
$scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.sort_by = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse;
};
});
希望你能帮忙。
【问题讨论】:
标签: javascript php json angularjs joomla