2014-10-08 53 views
0

我和獲取此異常:上市Rails的API數據的角度

Expected response to contain an array but got an object 

堂妹 IsArray的:真正的 如果生病使虛假和ofcource這個異常消失。

{"themes":[{"id":1,"name":"This is first then","description":"This is first then"},{"id":2,"name":"Second Themes","description":"Second Themes"},{"id":3,"name":"This is $th theme","description":"This is $th theme"}] 
} 

但我不知道如何從這個json檢索數據。

<tr ng-show="themes.length" ng-repeat="theme in themes"> 
       <td>{{theme.name}}</td> 
       <td>{{theme.description}}</td> 
      </tr> 

它顯示什麼。

請幫

回答

0

嘗試修改您的JSON迴應是這樣的:

[{"id":1,"name":"This is first then","description":"This is first then","created_at":"2014-10-08T10:37:08.208Z"},{"id":2,"name":"Second Themes","description":"Second Themes","created_at":"2014-10-08T11:28:54.900Z"},{"id":4,"name":"4th theme","description":"4th theme","created_at":"2014-10-09T05:13:35.605Z"}] 

您可以從軌道做主題/ index.json

object false 
child(@themes => :themes) do 
    extends "themes/show" 
end 

修改爲:

object @themes 
attributes :id, :name, :description, :created_at 
資源

,並isArray: true

0
$scope.obj = {"themes":[{"id":1,"name":"This is first then","description":"This is first then"},{"id":2,"name":"Second Themes","description":"Second Themes"},{"id":3,"name":"This is $th theme","description":"This is $th theme"}]} 

<tr ng-show="obj.themes.length > 0" ng-repeat="theme in obj.themes"> 
    <td>{{theme.name}}</td> 
    <td>{{theme.description}}</td> 
</tr>