Ember.js 访问控制器功能成员内的内容
我有一个这样的路线,控制器,视图。问题是我从视图中调用了控制器函数Ember.js 访问控制器功能成员内的内容,ember.js,Ember.js,我有一个这样的路线,控制器,视图。问题是我从视图中调用了控制器函数reloadTime,但在reloadTime函数中,我控制台了该控制器的内容,但它说它是未定义的。我的问题是如何在ember中访问此内容 App.ActivecallsRoute = Ember.Route.extend({ setupController:function(controller,model){ $.ajax({ url:'requests/activecalls.
reloadTime
,但在reloadTime
函数中,我控制台了该控制器的内容,但它说它是未定义的
。我的问题是如何在ember中访问此内容
App.ActivecallsRoute = Ember.Route.extend({
setupController:function(controller,model){
$.ajax({
url:'requests/activecalls.php',
type:'POST',
success:function(data){
App.Cdrglobal.set('active_call',data.length);
controller.set('content',data);
}
})
}
});
App.ActivecallsController = Ember.ArrayController.extend({
content:[],
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(){
console.log(this.get('content'));//console undefined
console.log(this.content);console undefined
}
});
App.ActivecallsView = Ember.View.extend({
didInsertElement:function(){
this.get('controller').reloadTime();
}
});
您正在正确访问
内容
属性。之所以得到未定义的
,是因为内容
属性实际上未定义
现在您的内容
未定义的原因是,Ember.js会自动将控制器的内容设置为路由中模型
挂钩的返回值
由于您没有定义模型
方法,因此如果此钩子为未定义
,则返回值,因此Ember.js将控制器内容
属性设置为未定义
解决方案:
创建仅返回空数组的虚拟模型挂钩:
App.ActivecallsRoute = Ember.Route.extend({
setupController:function(controller,model){
$.ajax({
url:'requests/activecalls.php',
type:'POST',
success:function(data){
App.Cdrglobal.set('active_call',data.length);
controller.set('content',data);
}
});
},
model: function() {
return [];
}
});
您正在正确访问
内容
属性。之所以得到未定义的
,是因为内容
属性实际上未定义
现在您的内容
未定义的原因是,Ember.js会自动将控制器的内容设置为路由中模型
挂钩的返回值
由于您没有定义模型
方法,因此如果此钩子为未定义
,则返回值,因此Ember.js将控制器内容
属性设置为未定义
解决方案:
创建仅返回空数组的虚拟模型挂钩:
App.ActivecallsRoute = Ember.Route.extend({
setupController:function(controller,model){
$.ajax({
url:'requests/activecalls.php',
type:'POST',
success:function(data){
App.Cdrglobal.set('active_call',data.length);
controller.set('content',data);
}
});
},
model: function() {
return [];
}
});