0

我有一个这样的控制器。在 reloadTime 函数中,我想修改此控制器内容的键的值。

App.ActivecallsController = Ember.ArrayController.extend({
    activeCalls:[],
    //obj:[],
    deleteCall:function(model){
       var obj = this.findProperty('ID',model.ID);
       App.Cdrglobal.set('active_call',App.Cdrglobal.active_call-1);
       this.removeObject(obj);
    },
    reloadTime:function(){
        var self=this;
        var inter = setInterval(function(){
            $(self.get('content')).each(function(k,v){
               self.set(self.content[k]['duration'],'00');
               clearInterval(inter);
            });
        },1000);
    }
});

内容是

[{"ID":1,"from_number":"1231654","carrier_ip":"123.156.12.1","to_number":"156816548","gw_ip":"156.245.15.12","duration":"12:14"},{"ID":2,"from_number":"1231654","carrier_ip":"123.156.12.1","to_number":"156816548","gw_ip":"156.245.15.12","duration":"15:44"},{"ID":3,"from_number":"1231654","carrier_ip":"123.156.12.1","to_number":"156816548","gw_ip":"156.245.15.12","duration":"52:24"},{"ID":4,"from_number":"1231654","carrier_ip":"123.156.12.1","to_number":"156816548","gw_ip":"156.245.15.12","duration":"52:20"}]
4

1 回答 1

2

我真的不明白,你想在那里实现什么用例,但这是我的尝试。在控制器中看到 jQuery 的使用真的很尴尬。而是使用 Ember 提供的收集方法。如您所见,我使用了Ember Arrays 提供的 forEach 方法

App.ActivecallsController = Ember.ArrayController.extend({
    activeCalls:[],
    //obj:[],
    deleteCall:function(model){
       var obj = this.findProperty('ID',model.ID);
       App.Cdrglobal.set('active_call',App.Cdrglobal.active_call-1);
       this.removeObject(obj);
    },
    reloadTime:function(){
        var self=this;
        var inter = setInterval(function(){
            self.forEach(function(contentItem){
              self.set("duration", "00");
            });
            clearInterval(inter);
        },1000);
    }
});

这是一个让您开始使用 Ember Collection 方法的基本示例。在您的情况下,使用 setEach会更容易:

App.ActivecallsController = Ember.ArrayController.extend({
    ...
    reloadTime:function(){
        var self=this;
        var inter = setInterval(function(){
            self.setEach("duration", "00");
            clearInterval(inter);
        },1000);
    }
});
于 2013-04-09T10:38:56.367 回答