ember.js - Access content inside a controller function ember -


i have route, controller, view this. problem called controller function reloadtime view in reloadtime function console content controller says undefined. question how access 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();    } }); 

you accessing content property correctly. reason why getting undefined because content property undefined.

now reason why content undefined, because ember.js automatically sets controller's content return value of model hook in route.

since didn't define model method, return value if hook undefined , therefore ember.js setting controller content property undefined.

solution:

create dummy model hook returns empty array:

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 [];   } }); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -