我正在为我的商店使用angularJS,并用Google表格中的数据替换产品json。
你能告诉我我在做什么错吗?
"use strict";
var productFactory = angular.module('productFactory', []);
productFactory.factory('productFactory', function ($scope, $http) {
$http.get("https://spreadsheets.google.com/feeds/list/MYAPIKEY/1/public/values?alt=json")
.success(function(response) {$scope.products = response.feed.entry;});
var productFactory = {};
var productId = product.gsx$id.$t;
var name = product.gsx$name.$t;
var category = product.gsx$category.$t;
var desc = product.gsx$description.$t;
var image = product.gsx$image.$t;
var price = product.gsx$price.$t;
var qty = product.gsx$qty.$t;
var variation = product.gsx$variation.$t;
productFactory.products = [
// {
// productId: 1,
// name: "Long Sleeve Black T-Shirt",
// category: "Long Sleeve",
// desc: "Made from 4.5oz 100% ring spun cotton.",
// image: "long_sleeve/t-shirt-man_front_black-long-2.jpg",
// price: 110,
// qty: 6,
// variation: ""
// }
];
return productFactory;
});
productFactory.products =我要替换的部分。谢谢您的帮助。
有人推荐了此方法,但仍然不起作用:
"use strict";
var productFactory = angular.module('productFactory', []);
productFactory.factory('productFactory', function ($scope, $http) {
$http.get("https://spreadsheets.google.com/feeds/list/MYAPIKEY/1/public/values?alt=json").success(function(response) {$scope.products = response.feed.entry;});
var productFactory = response.feed.entry,
responseLength = productFactory.length,
productFactory.products = [],
product;
for (var i = 0; i < responseLength; i++) {
product = productFactory[i];
productFactory.products.push({
value: product.gsx$id.$t.replace('productId: ', ''),
value: product.gsx$name.$t.replace('name: ', ''),
value: product.gsx$category.$t.replace('category: ', ''),
value: product.gsx$description.$t.replace('desc: ', ''),
value: product.gsx$image.$t.replace('image: ', ''),
value: product.gsx$price.$t.replace('price: ', ''),
value: product.gsx$qty.$t.replace('qty: ', ''),
value: product.gsx$variation.$t.replace('variation: ', '')
});
}
return productFactory;
});
有些事情不对。