访问控制器功能中的内容 [英] Access content inside a controller function ember
问题描述
reloadTime
,但在 reloadTime
函数中我控制了这个控制器的内容,但它说未定义
。我的问题是如何以ember方式访问此内容? App.ActivecallsRoute = Ember.Route.extend({
setupController:function(controller,model){
$ .ajax({
url:'requests / activecalls.php',
type:'POST',
success:function数据){
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.log(this.content);控制台未定义
}
});
App.ActivecallsView = Ember.View.extend({
didInsertElement:function(){
this.get('controller')。reloadTime();
}
});
您正在访问内容
属性正确。你未定义
的原因是因为内容
属性实际上是未定义的。
现在,您的 由于您没有定义一个 解决方案: 创建一个虚拟模型钩子这只是返回一个空数组: I have a route, controller, view like this. The problem is I called controller function
You are accessing the Now the reason why your Since you didn't define a Solution: Create a dummy model hook that just returns an empty array:
这篇关于访问控制器功能中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!内容
未定义的原因是因为Ember.js自动将控制器的内容设置为
$ b 模型
方法,返回值如果此钩子是 undefined
,因此Ember.js将控制器内容
属性设置为未定义
。
App.ActivecallsRoute = Ember.Route.extend({
setupController:function控制器,模型){
$ .ajax({
url:'requests / activecalls.php',
type:'POST',
success:function(data){
App.Cdrglobal.set('active_call',data.length);
con troller.set(内容,数据);
}
});
},
model:function(){
return [];
}
});
reloadTime
from view but in reloadTime
function I console the content for this controller but it says it is undefined
. My question is how to access this content in 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();
}
});
content
property correctly. The reason why you are getting undefined
is because the content
property is actually undefined.content
is undefined, is because Ember.js automatically sets the controller's content to the return value of the model
hook in the route.model
method, the return value if this hook is undefined
and therefore Ember.js is setting the controller content
property to undefined
.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 [];
}
});