IONIC 프레임 워크와 Angular JS를 사용하여 응용 프로그램을 작성 중이며 이온이 방출 한 Tinder 카드 기능 (http://ionicframework.com/blog/tinder-for-x/)을 사용하고 있습니다. JSON 파일을 읽고이 json 파일을 배열의 저장소로 사용하려고합니다. 나는이 작업을 수행 할 수있는 방법, 아래 정상적인 배열 내 코드Angular JS, json의 ionic reading
//Controller for Cards
angular.module('Pinder').controller('CardsCtrl', function($scope, TDCardDelegate) {
console.log('CARDS CTRL');
//Array of Cards - this should be moved to a service file.
var cardTypes = [
{id: 1, title: "Frank", image: 'img/Frank.png', desc:"This will be card Description", done: false },
{id: 2, title: "John Lewis", image: 'img/JohnLewis.png', desc:"This will be card Description", done: true },
{id: 3, title: "Generali", image: 'img/Generali.png', desc:"This will be card Description", done: true },
];
//Calls CardTypes array into 'cards'
$scope.cards = Array.prototype.slice.call(cardTypes, 0);
$scope.cardDestroyed = function(index) {
$scope.cards.splice(index, 1);
};
//Randomly adds a new card
$scope.addCard = function() {
var newCard = cardTypes[Math.floor(Math.random() * cardTypes.length)];
newCard.id = Math.random();
$scope.cards.push(angular.extend({}, newCard));
}
})
//Controller for swipe interface of the card.
.controller('CardCtrl', function($scope, TDCardDelegate) {
//Card swipe left function
$scope.cardSwipedLeft = function(index) {
console.log('LEFT SWIPE');
$scope.addCard();
};
//Card swipe right function
$scope.cardSwipedRight = function(index) {
console.log('RIGHT SWIPE');
$scope.cards[index].done = true;
$scope.addCard();
};
})
이 난 CardsCtrl이 오류를 얻을 JSON 방법을 사용하면 JSON 파일
//Controller for Cards
angular.module('Pinder').controller('CardsCtrl', function($scope, TDCardDelegate, $http) {
console.log('CARDS CTRL');
$scope.cards = [];
$http.get('../cards.json', function(cardTypes){
//Calls CardTypes array into 'cards'
$scope.cards = Array.prototype.slice.call(cardTypes, 0);
}, function(error) {
//handle error here
});
});
$scope.cardDestroyed = function(index) {
$scope.cards.splice(index, 1);
};
//Randomly adds a new card
$scope.addCard = function() {
var newCard = cardTypes[Math.floor(Math.random() * cardTypes.length)];
newCard.id = Math.random();
$scope.cards.push(angular.extend({}, newCard));
}
})
//Controller for swipe interface of the card.
.controller('CardCtrl', function($scope, TDCardDelegate) {
//Card swipe left function
$scope.cardSwipedLeft = function(index) {
console.log('LEFT SWIPE');
$scope.addCard();
};
//Card swipe right function
$scope.cardSwipedRight = function(index) {
console.log('RIGHT SWIPE');
$scope.cards[index].done = true;
$scope.addCard();
};
})
에서 읽는 내 코드입니다 기능이 아닙니다.
에 찾고 있던 답을 발견했다. 명령문을 닫는 데 필요한 경우에만'/} 오류 처리 '뒤에 두 개의'}};'가 있습니다. –
나는 그것을 보지 못했다고 믿는다. 올바른 구문으로도 내 json 파일에서 읽지 않습니다. – Adam