Usando ng-repeat para extraer datos de 2 archivos JSON diferentes

No obtengo ningún error, pero no puedo procesar mis datos. Mi estructura es simple en cuanto a que los archivos json en una carpeta, las vistas en otra, los scripts / controladores en otra. Simplemente usando el controlador para hacer el trabajo, ya que es un widget directo. Cualquier idea sobre lo que puede estar causando que esto falle ya que no estoy recibiendo errores y creo que mi asignación es correcta.

Mi código:

vista actualizada aquí:

{{ item.address }}

{{ item.address }}

{{ item.cost }}

  • {{ item.beds }}
  • {{ item.baths }}
  • {{ item.sq_ft }}

vista original:

 

Awesome Listings Widget

{{ item.value.address }}

{{ item.value.address }}

{{ item.value.cost }}

  • {{ item.value.beds }}
  • {{ item.value.baths }}
  • {{ item.value.sq_ft }}

mi controlador:

 'use strict'; angular.module('zillowTestApp') .controller('MainCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) { $scope.items = []; $http.get('#/batmanReality.json').then(function(response){ angular.forEach(response.data.__BATMAN_DATA__, function(value,key){ $scope.items.push({ address: key, cost: value.cost, beds: value.beds, baths: value.baths, sq_ft: value.sq_ft }); }) }); $http.get('#/supermanReality.json').then(function(response){ angular.forEach(response.data.__SUPERMAN_DATA__, function(value,key){ $scope.items.push({ address: value.address, price: value.cost, beds: value.beds, baths: value.baths, sq_ft: value.sq_ft }); }) }); }]); 

Y los 2 archivos JSON con sus objetos y propiedades.

 window.__BATMAN_DATA__ = { "1806 E. Wayne Lane, Fort Dodge, IA 50501": { "cost": "849,950", "beds": "5", "baths": "3", "sq_ft": "4050", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }, "1774 Kapow Drive, Hyattsville, MD 20782": { "cost": "419,950", "beds": "3", "baths": "2", "sq_ft": "1700", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }, "773 Duhnuhnuhna Street, Essex, MD 21221": { "cost": "524,999", "beds": "3", "baths": "2", "sq_ft": "1980", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }, "178 Pennyworth Avenue, Depew, NY 14043": { "cost": "619,999", "beds": "4", "baths": "1.5", "sq_ft": "2100", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" } }; 

y:

 window.__SUPERMAN_DATA__ = { "items": [ { "address": "7791 Luther Way, Knoxville, TN 37918", "price": "549999", "beds": "3", "baths": "2.5", "sqft": "3000", "built": "1976", "thumb": "http://fillmurray.com/150/150", "url": "http://zillow.com" }, { "address": "1774 Kapow Drive, Hyattsville, MD 20782", "price": "419950", "beds": "3", "baths": "2", "sqft": "1700", "built": "2001", "thumb": "http://stevensegallery.com/200/200", "url": "http://zillow.com" }, { "address": "3121 5th Street, Gotham, NY 27520", "price": "280000", "beds": "2", "baths": "1", "sqft": "", "built": "1948", "thumb": "http://fillmurray.com/150/150", "url": "http://zillow.com" }, { "address": "178 Pennyworth Avenue, Depew, NY 14043", "price": "619999", "beds": "4", "baths": "1.5", "sqft": "2100", "built": "2014", "thumb": "http://stevensegallery.com/200/200", "url": "http://zillow.com" } ] }; 

Como puede ver, hago referencia a ng-repeat con “item in items” y estructurado el http.get para agarrar de esa manera con el objeto. Ideas por favor?

Por favor revisa tu JSON. Piensa que JSON no es válido.

BatmanReality.json

 {"batman" : { "1806 E. Wayne Lane, Fort Dodge, IA 50501": { "cost": "849,950", "beds": "5", "baths": "3", "sq_ft": "4050", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }, "1774 Kapow Drive, Hyattsville, MD 20782": { "cost": "419,950", "beds": "3", "baths": "2", "sq_ft": "1700", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }, "773 Duhnuhnuhna Street, Essex, MD 21221": { "cost": "524,999", "beds": "3", "baths": "2", "sq_ft": "1980", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }, "178 Pennyworth Avenue, Depew, NY 14043": { "cost": "619,999", "beds": "4", "baths": "1.5", "sq_ft": "2100", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" }}} 

supermanReality.json

 {"superman" : { "items": [ { "address": "7791 Luther Way, Knoxville, TN 37918", "price": "549999", "beds": "3", "baths": "2.5", "sqft": "3000", "built": "1976", "thumb": "http://fillmurray.com/150/150", "url": "http://zillow.com" }, { "address": "1774 Kapow Drive, Hyattsville, MD 20782", "price": "419950", "beds": "3", "baths": "2", "sqft": "1700", "built": "2001", "thumb": "http://stevensegallery.com/200/200", "url": "http://zillow.com" }, { "address": "3121 5th Street, Gotham, NY 27520", "price": "280000", "beds": "2", "baths": "1", "sqft": "", "built": "1948", "thumb": "http://fillmurray.com/150/150", "url": "http://zillow.com" }, { "address": "178 Pennyworth Avenue, Depew, NY 14043", "price": "619999", "beds": "4", "baths": "1.5", "sqft": "2100", "built": "2014", "thumb": "http://stevensegallery.com/200/200", "url": "http://zillow.com" } ]}} 

y

html:

 

{{ item.address }}

{{ item.address }}

{{ item.cost }}

  • {{ item.beds }}
  • {{ item.baths }}
  • {{ item.sq_ft }}

En tu Json, ventana. BATMAN_DATA y ventana. SUPERMAN_DATA no es una matriz, es un objeto de objetos. Así que por favor modifique su json as-

 window.__SUPERMAN_DATA__ = [ { "address": "7791 Luther Way, Knoxville, TN 37918", "price": "549999", "beds": "3", "baths": "2.5", "sqft": "3000", "built": "1976", "thumb": "http://fillmurray.com/150/150", "url": "http://zillow.com" }, { "address": "1774 Kapow Drive, Hyattsville, MD 20782", "price": "419950", "beds": "3", "baths": "2", "sqft": "1700", "built": "2001", "thumb": "http://stevensegallery.com/200/200", "url": "http://zillow.com" }, { "address": "3121 5th Street, Gotham, NY 27520", "price": "280000", "beds": "2", "baths": "1", "sqft": "", "built": "1948", "thumb": "http://fillmurray.com/150/150", "url": "http://zillow.com" }, { "address": "178 Pennyworth Avenue, Depew, NY 14043", "price": "619999", "beds": "4", "baths": "1.5", "sqft": "2100", "built": "2014", "thumb": "http://stevensegallery.com/200/200", "url": "http://zillow.com" } ]; window.__BATMAN_DATA__ = [ { "1806 E. Wayne Lane, Fort Dodge, IA 50501": { "cost": "849,950", "beds": "5", "baths": "3", "sq_ft": "4050", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" } }, {"1774 Kapow Drive, Hyattsville, MD 20782": { "cost": "419,950", "beds": "3", "baths": "2", "sq_ft": "1700", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" } }, { "773 Duhnuhnuhna Street, Essex, MD 21221": { "cost": "524,999", "beds": "3", "baths": "2", "sq_ft": "1980", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" } }, { "178 Pennyworth Avenue, Depew, NY 14043": { "cost": "619,999", "beds": "4", "baths": "1.5", "sq_ft": "2100", "img": "http://stevensegallery.com/200/200", "url": "http://trulia.com" } } ];