Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 获取JSON数据,但它';s未加载到Ember.js中的视图中_Codeigniter_Rest_Ember.js_Codeigniter Restserver - Fatal编程技术网

Codeigniter 获取JSON数据,但它';s未加载到Ember.js中的视图中

Codeigniter 获取JSON数据,但它';s未加载到Ember.js中的视图中,codeigniter,rest,ember.js,codeigniter-restserver,Codeigniter,Rest,Ember.js,Codeigniter Restserver,我正在根据控制台获取JSON,但我一直得到这个错误 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" 而这个错误, Assertion failed: Your server returned a hash with the key 0 bu

我正在根据控制台获取JSON,但我一直得到这个错误

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" 
而这个错误,

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":"jeanne_s@earth.com","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库。我的代码可能有什么问题,或者后端有什么问题?

余烬数据要求json响应采用特定格式。基本键必须是模型的名称。在您的情况下,没有基本密钥

示例:您将返回以下内容

[{"id":"1",
  "last_name":"Solow",
  "first_name":"Jeanne",
  "suffix":null,
  "expiration":"2013-11-15",
  "email":"jeanne_s@earth.com",
  "street":"16 Ludden Dr."}, {etc}]
但是余烬需要这样的东西:

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

您需要更改来自服务器的json响应,或者使用另一个库作为与服务器的接口

Ember数据要求json响应采用特定格式。基本键必须是模型的名称。在您的情况下,没有基本密钥

示例:您将返回以下内容

[{"id":"1",
  "last_name":"Solow",
  "first_name":"Jeanne",
  "suffix":null,
  "expiration":"2013-11-15",
  "email":"jeanne_s@earth.com",
  "street":"16 Ludden Dr."}, {etc}]
但是余烬需要这样的东西:

{'users': [{"id":"1",
  "last_name":"Solow",
  "first_name":"Jeanne",
  "suffix":null,
  "expiration":"2013-11-15",
  "email":"jeanne_s@earth.com",
  "street":"16 Ludden Dr."}, {etc}]}
您需要更改来自服务器的json响应,或者使用另一个库作为与服务器的接口