2014-12-23 3 views
0

json 응답 객체를 로컬 저장소에 저장하려고합니다. 네트워크를 사용할 수 없으면 서버에서 로컬 스토리지의 데이터를 읽을 수 있습니다. 나는 그런 조건을 어디에도 보지 못했다.
미리 감사드립니다.

JSON
[
  {
    "TID": "3388",
    "이름": "아다지오 바",
    "범주 이름": "엔터테인먼트/바 "
   "갑판 ":"썬 데크 16 "
 },
  {
    "TID": "3439",
    "이름": "보티첼리 식당",
    "범주 이름": "음식과 식사",
    "갑판": "피에스타 갑판 6 "
 },
  {
   "TID ":"3399 ",
   "이름 ":"카페 카리브 ",     "범주 이름": "음식과 식사",
    "갑판": "리도 데크 15"
 },
  {
    "TID": "3377",
"스파 풀, 스포츠 &",
    "갑판":     "이름": "센터 코트",
    "CATEGORY_NAME" "스타 D 에크 19 "
 }
]

컨트롤러
netwok를 사용할 수 없을 때 JSON 객체를 읽는 방법은 무엇입니까?

'use strict'; 
var princess_at_sea = angular.module('princess_at_sea', []) 
princess_at_sea.controller("locationList", function($scope, $http){ 
    $scope.locationList = null; 
    $http.get("location.json") 
     .success(function(data){ 
      $scope.locationList = data;   
      var indexedloc = []; 
      $scope.locationListToFilter = function(){ 
       indexedloc = []; 
       return $scope.locationList; 
      } 
      $scope.filterLocation = function(Loc){ 
       var locationIsNew = indexedloc.indexOf(Loc.category_name) == -1; 
       if(locationIsNew){ 
        indexedloc.push(Loc.category_name);     
       } 
       return locationIsNew; 
      } 
      $scope.returnFilterLoc = function(){return indexedloc}; 
     }) 
     .error(function(data) { 
      $("div.content").html("Error"); 
     }); 
}); 

HTML enter image description here

가 나는 URL을 너무 http://jsfiddle.net/s1812ap8/

+4

혹시 서버에 접속 해 보았습니까? 그렇다면 실패한 경우 ('.error()'핸들러에서) 로컬 저장 장치에서 객체를로드 할 수 없습니까? – mason

답변

0

을 추가 한 당신은 N 것 Mason이 위에 언급 한 것을 수행하지만 0 상태 코드에 대해주의를 기울이십시오.

function error(response) { 
    if (response.status === 0) { 
     errorStatus = 'No connection. Verify application is running.'; 
    } else if (response.status == 401) { 
     errorStatus = 'Unauthorized'; 
    } else if (response.status == 405) { 
     errorStatus = 'HTTP verb not supported [405]'; 
    } else if (response.status == 500) { 
     errorStatus = 'Internal Server Error [500].'; 
    } else { 
     errorStatus = response.data; 
    } 
    } 
관련 문제