无法从angularjs中的$cookieStore获取和理解数据
我在stackoverflow上对此进行了大量搜索,但我无法找到该问题的相关答案。 我正在将一个列表插入angular cookiestore,并试图将该列表提取到另一个angular控制器中。但我无法找到它的数据格式。我正试图像这样在cookies中插入数据无法从angularjs中的$cookieStore获取和理解数据,angularjs,cookiestore,Angularjs,Cookiestore,我在stackoverflow上对此进行了大量搜索,但我无法找到该问题的相关答案。 我正在将一个列表插入angular cookiestore,并试图将该列表提取到另一个angular控制器中。但我无法找到它的数据格式。我正试图像这样在cookies中插入数据 $scope.addToCart = function (Picture1, ProductName, UnitPrice) { var count = 0; var item = new cartIte
$scope.addToCart = function (Picture1, ProductName, UnitPrice) {
var count = 0;
var item = new cartItem(Picture1, ProductName, UnitPrice);
$scope.items.push(item);
$cookieStore.put('StyleStoreCart', $scope.items);
//$cookies.StyleStoreCart = $scope.items;
$scope.getCookies = $cookieStore.get('StyleStoreCart');
console.log($scope.getCookies);
$scope.Itemcount= $scope.Itemcount+1
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
toastr.warning('Item Added to Your Cart', 'Cart Update')
}
$scope.items = $cookieStore.get('StyleStoreCart');
var itemz=$scope.items
for (var i = 0; i < itemz.length; i++) {
var item = itemz[i];
console.log("item", item[0].Object);
// debugger;
var ctr = i + 1;
//data["item_number_" + ctr] = item.sku;
data["item_name_" + ctr] = item[i].Object.ProductName;
data["quantity_" + ctr] = 1;
data["amount_" + ctr] = item.UnitPrice;
}
我得到的cookieStore价值是这样的
$scope.addToCart = function (Picture1, ProductName, UnitPrice) {
var count = 0;
var item = new cartItem(Picture1, ProductName, UnitPrice);
$scope.items.push(item);
$cookieStore.put('StyleStoreCart', $scope.items);
//$cookies.StyleStoreCart = $scope.items;
$scope.getCookies = $cookieStore.get('StyleStoreCart');
console.log($scope.getCookies);
$scope.Itemcount= $scope.Itemcount+1
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
toastr.warning('Item Added to Your Cart', 'Cart Update')
}
$scope.items = $cookieStore.get('StyleStoreCart');
var itemz=$scope.items
for (var i = 0; i < itemz.length; i++) {
var item = itemz[i];
console.log("item", item[0].Object);
// debugger;
var ctr = i + 1;
//data["item_number_" + ctr] = item.sku;
data["item_name_" + ctr] = item[i].Object.ProductName;
data["quantity_" + ctr] = 1;
data["amount_" + ctr] = item.UnitPrice;
}
请告诉我如何获取此数据以及数据的格式。您正在存储一个包含cartItem实例的数组(通过
新建cartItem(Picture1,ProductName,UnitPrice)
创建)。该数组被转换为JSON并存储在cookie中。然后,当您将其取回时,JSON字符串将被解析并转换回JS对象数组。这是有据可查的:你能告诉我怎样才能从这里获取数据吗@不,我不能,因为我不知道你的行李是什么样子。做一个console.log(angular.toJson($cookieStore.get('StyleStoreCart'))
,你就会得到你得到的JSON表示。或者只需在浏览器开发工具窗口的“资源/cookies”选项卡中查找它。不要使用$cookieStore,因为它已被弃用。请参见-使用$cookies而不是它。请告诉我们您必须获取哪些数据。[{“图片”:“/Upload/1002493_42625070820813_2073699715_n.jpg”,“name”:“Punjabi Susts 5”,“price”:1000},{“图片”:/Upload/225743_564835133537020_1509910106_n.jpg”,“name”:“Punjabi Susts”,“price”:1000}@User2我想获取这些数据