2013-07-24 1 views
1

내가 콘솔에 따라, JSON을 얻고있다하지만이 오류가 계속에서보기에로드하기 아니에요 는 JSON 데이터를 얻기 있지만, Ember.js

Assertion failed: Your server returned a hash with the key 0 but you have no mapping for it 

이 오류

,

TypeError {} "Cannot call method 'toString' of undefined" 

가 여기에 샘플 JSON 응답이다,

[{"id":"1","last_name":"Solow","first_name":"Jeanne","suffix":null,"expiration":"2013-11-15","email":"[email protected]","street":"16 Ludden Dr.","city":"Austin","state":"TX","zip":"33347","phone":"964-665-8735","interests":"Great Depression,Spanish-American War,Westward movement,Civil Rights,Sports"}, {etc..} 

은 여기 내 app.js,이다

App = Ember.Application.create({}); 

App.Store = DS.Store.extend({ 
    revision : 12, 
    adapter : DS.RESTAdapter.extend({ 
     url : 'http://ankur1.local/index.php/api/example/users/format/json', 
     dataType : 'jsonp', 
    }) 
}); 

App.IndexRoute = Ember.Route.extend({ 
    renderTemplate : function() { 
     this.render('myTemplate', { 
      controller : 'Index' 
     }); 
    }, 
    model : function() { 
     return App.myTemplate.find(); 
    } 
}); 

App.IndexController = Ember.Controller.extend({ 
    user : Ember.Object.create({ 
     name : "" 
    }), 
    userNameBinding : Ember.Binding.oneWay("this.user.name"), 
    clickButton : function(name) { 

     if ($("#name").val().trim().length === 0) { 
      alert("text box is empty"); 
     } else { 

     } 
    } 
}); 

App.myTemplate = DS.Model.extend({ 
    id : DS.attr('int'), 
    last_name : DS.attr('string'), 
    first_name : DS.attr('string'), 
    suffix : DS.attr('string'), 
    expiration : DS.attr('date') 
}); 

필자는 Phil Sturgeon의 Codeigniter RestServer Library를 백엔드에서 사용하고 있습니다. 내 코드에 어떤 문제가 있거나 백엔드에서 문제가 될 수 있습니까?

답변

1

Ember 데이터를 사용하려면 json 응답이 특정 형식이어야합니다. 기본 키는 모델의 이름이어야합니다. 귀하의 경우 기본 키가 없습니다.

예 : 다음

[{"id":"1", 
    "last_name":"Solow", 
    "first_name":"Jeanne", 
    "suffix":null, 
    "expiration":"2013-11-15", 
    "email":"[email protected]", 
    "street":"16 Ludden Dr."}, {etc}] 

을 반환하고 있지만 엠버는 다음과 같이해야합니다 :

{'users': [{"id":"1", 
    "last_name":"Solow", 
    "first_name":"Jeanne", 
    "suffix":null, 
    "expiration":"2013-11-15", 
    "email":"[email protected]", 
    "street":"16 Ludden Dr."}, {etc}]} 

가 어느 서버에서 JSON 응답을 변경하거나 다른 사람의 사용을 만들 필요를 서버와의 인터페이스를위한 라이브러리.