Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
Ember.js 未捕获类型错误:对象#<;对象>;没有方法';设置';_Ember.js - Fatal编程技术网

Ember.js 未捕获类型错误:对象#<;对象>;没有方法';设置';

Ember.js 未捕获类型错误:对象#<;对象>;没有方法';设置';,ember.js,Ember.js,当我尝试将我的“内容”设置为customerList时,会出现以下错误: 未捕获的TypeError:对象#对象没有方法“set” 这是我的密码: App.TableController = Em.ArrayController.extend({ init: function() { this._super(); this.getData(); }, getData: function() { $.get('data/customer.json', function(

当我尝试将我的“内容”设置为customerList时,会出现以下错误:

未捕获的TypeError:对象#对象没有方法“set”

这是我的密码:

  App.TableController = Em.ArrayController.extend({
init: function() {
    this._super();
    this.getData();
},
getData: function() {
    $.get('data/customer.json', function(data) {
        var customerList = Ember.A([]);
        data.forEach(function(item) {
            var customer = App.overv.create({
                incidient: item.incidient,
                customer: item.customer,
                machine: item.machine,
                priority: item.priority

            });
            customerList.pushObject(customer);
        });
        this.set('content', customerList);

    });
}});
我也用App.router.tableController.set('content',customerList)试过,但ember再也认不出控制器了。对于1.0.0 pre 2,第二个示例非常有效。
现在我试着找出我做错了什么或可能理解错了什么。

在局部变量self中保留对这一点的引用。请参阅下面的代码

App.TableController = Em.ArrayController.extend({
init: function() {
    this._super();
    this.getData();
},
getData: function() {
    var _self = this;
    $.get('data/customer.json', function(data) {
        var customerList = Ember.A([]);
        data.forEach(function(item) {
            var customer = App.overv.create({
                incidient: item.incidient,
                customer: item.customer,
                machine: item.machine,
                priority: item.priority

            });
            customerList.pushObject(customer);
        });
        _self.set('content', customerList);

    });
}});

可能只是AJAX回调上下文的问题。。。你可以试试这个:

App.TableController = Em.ArrayController.extend({
  init: function() {
      this._super();
      this.getData();
  },
  getData: function() {
      $.ajax({
        url: 'data/customer.json',
        dataType: 'json',
        context: this
      }).success(function(data, textStatus, jqXHR) { 
        var customerList = Ember.A([]);
        data.forEach(function(item) {
            var customer = App.overv.create({
                incidient: item.incidient,
                customer: item.customer,
                machine: item.machine,
                priority: item.priority

            });
            customerList.pushObject(customer);
        });
        this.set('content', customerList);
      });
  }
});

指定
TableController
作为回调的上下文。

this
在中指定:
this.set('content',customerList)看起来不是控制器(但可能是
窗口
)。如果在
getData
的第一行定义:
var self=this
,然后将
this
替换为
self
,则应该可以使用。