【发布时间】:2014-11-10 21:47:04
【问题描述】:
在 cookiestore 中存储数组时遇到问题。 尝试将数组添加到 cookiestore 中,以便以后可以访问它。 JS
angular.module('myApp', ['ngCookies']);
function CartForm($scope, $cookieStore) {
$scope.invoice.items = $cookieStore.get('items');
$scope.addItem = function() {
$scope.invoice.items.push({
qty: 1,
description: '',
cost: 0
});
$scope.invoice.items = $cookieStore.put('items');
},
$scope.removeItem = function(index) {
$scope.invoice.items.splice(index, 1);
$scope.invoice.items = $cookieStore.put('items');
},
$scope.total = function() {
var total = 0;
angular.forEach($scope.invoice.items, function(item) {
total += item.qty * item.cost;
})
return total;
}
}
【问题讨论】:
-
@user3428728 这个问题你解决了吗
标签: javascript arrays angularjs cookiestore