mardi 21 mai 2019

accessing controller properties within controller function in ember

Can't able to access the controller property within a controller function

App.ViewRController = Ember.Controller.extend({ datas:null, actions:{

viewfile:function(){
    let filename = this.get('filename');
    let count=0;
    let data;
            let self = this;
    if (filename!=null)
    {
        filename=filename.trim();
        if(filename.length>0)
        {

            try{
            let obj= new XMLHttpRequest();
            obj.onreadystatechange=function(){
            if(obj.readyState==4 && obj.status ==200)
                {

                    let json=obj.responseText;
                    console.log(self);
                    data = JSON.parse(json);
                    self.set(datas,data);


                }

            }

            let params = "filename="+filename;
            obj.open("POST","view");
            obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            obj.send(params);
            //this.set('datas',data);
            }
            catch(e){alert(e);}
        }
        else
            alert("enter filename");
        }
        else
            alert("enter filename");
    }

}

the template should will iterrate the datas object with properties. but I couldn't set the datas property within the function in the controller.




Aucun commentaire:

Enregistrer un commentaire