2016-07-13 5 views
-1

После вызова АНИ я получил следующие данные

$scope.twotap_builtin_cart = { 
     "sites":{ 
       "571fb46730bb1f373d00bdb4":{ 
         "info":{"logo":"https://core.twotap.com/system/sites/logos/571f/b467/30bb/1f37/3d00/bdb4/small/571fb46730bb1f373d00bdb4.png?1468389436927", 
         "name":"Overstock", 
         "url":"overstock.com" 
       },    
       "currency_format":"$AMOUNT", 
       "coupon_support":false, 
       "gift_card_support":false, 
       "checkout_support":["noauthCheckout"], 
       "shipping_countries_support":["United States of America"], 
       "billing_countries_support":["United States of America"], 
       "shipping_options":{"cheapest":"Default shipping option"}, 
       "returns":"<p><span style=\"font-size:16px\"><strong>Overstock Return Policy</strong></span></p>\r\n\r\n<p>You can initiate a return for most new and unopened items&nbsp;within 30 days of delivery for a full refund.* You must return items in new or unused condition with all original materials included with the shipment. We must receive your returned items at our processing facility within 45 days of delivery (see&nbsp;Product-Specific Return Policies&nbsp;for exceptions). We inspect all returned items and award a partial refund for opened or used products. If the return is a result of our error or defective product, we will refund the full cost of the merchandise and shipping charges.</p>\r\n\r\n<p>If you initiate a return after 30 days, we may issue a partial refund* depending on elapsed time and condition of merchandise.</p>\r\n\r\n<p><strong>Defective Product and Returns Due to Our Error</strong></p>\r\n\r\n<p>You may return defective items, items damaged at the time of receipt, and incorrect items received without penalty.** Your return shipping charges will be waived.</p>\r\n\r\n<p>When we receive your return, we inspect the item and provide a replacement or issue a refund. If the product is not defective, return shipping fees will apply and/or a partial refund may be issued.</p>\r\n\r\n<p><strong>Products Returned After 30 days</strong></p>\r\n\r\n<ul>\r\n\t<li>Because products devalue over time, we offer partial refunds for items returned over 30 days after delivery</li>\r\n\t<li>We may reduce the refund based on the condition of the merchandise</li>\r\n\t<li>We may also deduct the original and return shipping charges from your refund</li>\r\n\t<li>If we send you a replacement item, we must receive the original item at our warehouse within 30 days your return initiation. Otherwise, we will charge you full price for the replacement item</li>\r\n</ul>\r\n\r\n<p><em>For more about return policy rules and exceptions you can visit :&nbsp;https://help.overstock.com/app/answers/detail/a_id/1</em></p>\r\n", 
       "add_to_cart":{"a6eda98b2e60363a67efb985ef622cea":{"original_url":"http://www.jdoqocy.com/click-3726866-10654383?url=http%3A%2F%2Fwww.overstock.com%2F7281112%2Fproduct.html%3FTRACK%3Daffcjfeed%26CID%3D207442%26fp%3DF","clean_url":"http://www.overstock.com/7281112/product.html?CID=207442", 
       "weight":"1000", 
       "status":"done", 
       "required_fields":{ 
        "quantity":{ 
          "data":[{"input_type":"text","input_name":"INPUT"}]}}, 
          "discounted_price":null, 
          "original_price":null, 
          "pickup_support":false, 
          "url":"http://www.overstock.com/7281112/product.html?TRACK=affcjfeed&CID=207442&fp=F","required_field_values":{},"required_field_names":["quantity"],"categories":["Sports & Toys","Toys & Hobbies","Games & Puzzles","Board Games"],"description":"<p>ITEM#: 14756475</p> From a different age when people had time to sit and play games together, the Britannia Games Compendium is packed full of fun. Based on a product from the 1940s the Britannia Games Compendium has something for all ages.\n<br><br>\n<ul>\n<li>Brand: Perisphere and Trylon</li>\n<li>The Britannia Compendium of Games</li>\n<li>Model: PTRG-1088</li>\n<li>Based on a product from the 1940s the Britannia Games Compendium has something for all ages</li> <li>Beautifully made and highly collectable</li>\n<li>Number of players: 1 or more</li>\n<li>Includes: Chess, Draughts, Dominoes, Pick-up Sticks, Snap, Tiddlywinks, Playing Cards, Muggins, Poker Dice, Horse Racing Game, one (1) multiple fold-out game board, and instructions</li>\n<li>Recommended for ages 5 years and older</li>\n</ul>","alt_images":["http://ak1.ostkcdn.com/images/products/7281112/Perisphere-and-Trylon-The-Britannia-Compendium-of-Games-f17b48f6-8c81-4a0e-af12-fa2e3d97ac25_320.jpg"],"image":"http://ak1.ostkcdn.com/images/products/7281112/Perisphere-and-Trylon-The-Britannia-Compendium-of-Games-f17b48f6-8c81-4a0e-af12-fa2e3d97ac25_600.jpg","price":"$37.49","title":"Perisphere and Trylon The Britannia Compendium of Games"}}}},"user_id":null,"unknown_urls":[],"cart_id":"5785d83c493bfb7f2a352cde","notes":null,"country":"us","stored_field_values":{},"message":"done","description":"AddToCart has been completed.","product_urls":[]} 

Тогда я сохранил эти данные внутри печенья.

$cookies['xxx'] = $scope.twotap_builtin_cart; 

Теперь, когда я попытался извлечь эти данные из файлов cookie, он показал меня как Object. Я пытался напечатать его в консоли он показал объект Object

var t = $cookies['xxx']; 
console.log(t); 
$scope.recentItemsx = angular.toJson(t); 
console.log($scope.recentItemsx); 
console.log(JSON.parse($cookies['xxx'])); 

Я попытался JSON.parse, anglar.toJson и jsonstringify. Ничто не может решить эту

Я попытался с печеньем магазин

$cookieStore.put('recentx',$scope.twotap_builtin_cart); 

Я также получил следующее предупреждение Cookie в консоли

«RecentX», возможно, не установлен или переполнена, потому что он был слишком большим (6675> 4096 байт)! в другой контроллер я распечатаны

console.log($cookieStore.get('recentx')); 

Это дает мне выходной [объект Object]. Я не могу с этим работать. Мне нужны данные json для ng-repeat цели Я не могу putObject или Get Object, потому что они предназначены для угловой версии больше 1,4

+1

пожалуйста, поделитесь скрипку, чтобы мы могли воспроизвести и помочь вам – Saqueib

ответ

0

Попробуйте использовать JSON.stringify (t), чтобы преобразовать его в строку, затем JSON.parse (t) превратить его в JSON.

Или попробуйте angular.toJson(t)

+0

уаг J = JSON.stringify (т); console.log (JSON.parse (j)); , который напечатал [объект объекта] – Rajib

0

Во-первых, чтобы сохранить внутри печенья

var x= angular.toJson($scope.twotap_builtin_cart); 
$cookies['xxx']= x; 

Чтобы извлечь из печенья

var t = $cookies['xxx']; 
var pota = angular.fromJson(t); 
console.log(pota); 

Он должен работать для всех подобных данных в формате JSON. Но для моего случая данные слишком велики. Поэтому я не смог сохранить куки. Теперь я использую localstorage. Сначала используйте службу $ window и введите $ window внутри контроллера. Чтобы установить

var ret= angular.toJson($scope.twotap_builtin_cart); 
    $window.localStorage.setItem('recent',ret); 

Чтобы получить

if(angular.isDefined($window.localStorage.getItem('recent'))); 
     { 
     var tem =$window.localStorage.getItem('recent'); 
     var pota = angular.fromJson(tem); 
     console.log(pota); 
     }