使用ember中的controller属性更改单选按钮值

时间:2014-07-07 10:09:06

标签: javascript jquery ember.js handlebars.js

我正在获取radiobutton值,并希望将所选按钮值设置为控制器属性为isSelected = fetchedvalue,我无法绑定和设置。          通过onclick我得到了以下错误,我无法更改模板。没有点击我可以轻松使用renderto另一个模板。

HTML

    <script type="text/x-handlebars">
       <div {{bind-attr class=":div_class"}}>    
         <div {{bind-attr class=":div_title"}}>{{title}}</div>
         <div style="margin-top:5px;color:red;"><strong>please check any radio box to fetch from different folders</strong>
        </div>
        {{#each images}}
          <div style="margin-top:5px;font-family:Arial, Helvetica, sans-serif;">
          <label>{{view Ember.RadioButton name="selectionTest" selectionBinding="isSelected" value=this }}<span {{bind-attr class=":radio_textstyle"}}>{{this}}</span>
          </label>
          </div>
        {{/each}}        
        <div> 
       <button {{action "submitFolderPath"}}>submit</button> </div>
      </div>  
    </script>

JS

    App.Router.map(function() {
          //this.route('imageList');
      });

     App.ApplicationController = Ember.Controller.extend({
     title: 'Fetch Images From Folder Path',
     isSelected:'images',
     images : ['images','imagesList','imagesFolder','myFolder'],
     actions :{
        submitFolderPath : function(){
                         alert('path::'+this.get('isSelected'));
            //          alert('path::'+path);
            //this.transitionTo('imageList');
        }
     }
     })

    App.ApplicationRoute = Ember.Route.extend({

    });

    Ember.RadioButton = Ember.View.extend({  

    tagName : "input",
    type : "radio",
    attributeBindings : [ "name", "type", "value", "checked:checked:" ],
    click : function() {
        path = this.$().val();
          this.set('App.ApplicationController').set('isSelected',this.$().val());
        this.set("selection", this.$().val());
    },
    checked : function() {
        return this.get("value") == this.get("selection");   
    }.property()
});

0 个答案:

没有答案