我有和应用程序,需要输入报价(纯度,重量,总计),并将其推至$ scope.quote:AngularJS/Restangular索引JSON数据提取
// Controller action //
$scope.quote.push({
total: ((($scope.karat * $scope.spot) * $scope.percentage)/20) * $scope.estimatedWeight,
karat: $scope.karat * 100,
description: $scope.description,
actualWeight: $scope.actualWeight,
estimatedWeight: $scope.estimatedWeight,
percent: $scope.percentage * 100,
spot: $scope.spot
})
和
// Factory //
app.factory('quoteFactory', function() {
var quote = [];
var factory = {};
factory.getQuote = function() {
return quote;
};
return factory;
})
和后/保存报价结束后
$scope.save = function() {
var now = $scope.getDate();
$scope.quote.push({
createdOn: $scope.getDate()
})
Restangular.all('quote').post($scope.quote).then(function(quote){
$location.path('#/scrap')
});
};
当试图访问列表或编辑的报价JSON我无法访问所有的通知因为JSON结构需要。
{
"0": {
"total": 401.79040000000003,
"karat": 74,
"description": "Rings",
"actualWeight": 12,
"estimatedWeight": 11,
"percent": 80,
"spot": 1234
},
"1": {
"total": 560.7296,
"karat": 56.8,
"description": "Test",
"actualWeight": 22,
"estimatedWeight": 20,
"percent": 80,
"spot": 1234
},
"2": {
"total": 48.5625,
"karat": 92.5,
"description": "Testing",
"actualWeight": 80,
"estimatedWeight": 75,
"percent": 70,
"spot": 20
},
"3": {
"createdOn": "2013-11-26T21:26:42.253Z"
},
"_id": {
"$oid": "52951213e4b05f03172f14e7"
}
}
每个索引都代表报价和createdOn信息的行项目。我试图弄清楚的是,如果有办法可以访问所有订单项信息而无需调用每个单独的索引?
我查看了一些lodash /下划线,想到重构后端...并不确定从哪里去。
Complete project code at github
你是如何创建的JSON?索引看起来不自然,如果我'''JSON.stringify'''一个数组,通常不会附带包含索引 – Samuel
或更具体; JSON从哪里来?服务器是否读取它?我会建议修复JSON,尽管它的格式很古怪,但并不试图读取它。 – Samuel
也许因为工厂正在推进var quote = []导致索引。但是,如果更改为{}以引用将使用什么方法替换$ scope.quote.push() – Yahtaa