简体   繁体   中英

Emberjs: In my template I can't get a value from a form my controller

I create a template and it's controller and i set a variable(value) in controller but when i try to access in template noting to happen. my controller is:

    App.AboutController = Ember.Controller.extend({
    info:null,
    init: function() {
        console.log("yes i am in About controller");
        info = post["about"];
    },
  actions: {
    getdata1:function(data){
    console.log("get data",data);
    info = post[data];
    console.log(info);
    }

  }

and Template is:

<script type="text/x-handlebars" id="about" data-template-name="about">
<div class="col-xs-6 middlesubBody">
               {{info}}
           </div>
            <div class="col-xs-3 rightsubBody">
                <div id="column">
                        <div
                        {{action "getdata1" "about"}}> About</div>
                        <div>
</div>
</script>

MY Action is working fine but info value is not set to template.i want to dynamic binding . I think i am wrong but i don't know where is problem.

You need to use this.set('info', value) instead of info = value . Also, you use post many times, but it isn't defined anywhere. I have to assume that you have defined it somewhere:

App.AboutController = Ember.Controller.extend({
  info: null,
  init: function() {
    console.log("yes i am in About controller");
    this.set('info', post["about"]);
    this._super(); // you need this to avoid unexpected behavior
  },
  actions: {
    getdata1: function(data) {
      console.log("get data",data);
      this.set('info', post[data]);
      console.log(this.get('info'));
    }
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM