我有一个数组对象的函数。在angularJs中将ajax响应推送到数组中
$http({
method: 'GET',
url: 'select.php'
}).then(function success(response) {
alert(response);
//$scope.posts=response.data;
}, function error(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
}
);
function store() {
this.products = [
new product("APL", "Apple", "Eat one every…", 12, 90, 0, 2, 0, 1, 2),
new product("AVC", "Avocado", "Guacamole…", 16, 90, 0, 1, 1, 1, 2),
new product("BAN", "Banana", "These are…", 4, 120, 0, 2, 1, 2, 2)
];
}
在上面的代码中我们传递一些静态数据,而是我试图推它来自另一个文件作为Ajax响应一些动态数据。
所以我怎么能使它动态。我已经试过这样
function store() {
this.products = [
//new product("APL", "Apple", "Eat one every…", 12, 90, 0, 2, 0, 1, 2),
//new product("AVC", "Avocado", "Guacamole…", 16, 90, 0, 1, 1, 1, 2),
//new product("BAN", "Banana", "These are…", 4, 120, 0, 2, 1, 2, 2)
$scope.product.push(response.data);
];
}
但它不工作。任何想法我怎么能做到这一点?
你必须把$ scope.product.push(response.data);在ajax请求 – Vivz
$ scope.products而不是$ scope.product的情况下,如果你没有注意到新产品()的错字 – rrd
,这个应该重复取决于总行数据的权利? –