2016-11-08 53 views
0

Component.js - 我來到這裏我的按鈕值,並將其更改:更改按鈕文字與Ember綁定,不使用jQuery

actions: { 
    changeValue: function() { 
     this.$().on('click', '.cellValue', function(event) { 
      if ($(this).text() == '|') { 
       $(this).text('-'); 
       $(this).val('-'); 
      } else if ($(this).text() == '-') { 
       $(this).text('|'); 
       $(this).val('|'); 
      } else { 
      } 
     }); 
    } 
} 

Template.hbs - 有一個表裏面td按鈕哪個文本我想改變:

<table> 
    {{#each-in rows as |table tableRow|}} 
    {{#each tableRow as |singleRow|}} 
    <tr class="as"> 
     {{#each singleRow as |tableRows|}} 
     <td> 
      <button id="button_id"{{action "changeValue"}} class="cellValue" value="{{tableRows}}">{{tableRows}}</button> 
     </td> 
     {{/each}} 
    </tr> 
    {{/each}} 
{{/each-in}} 

回答

1

我做了這個旋鈕,告訴你如何更新你的按鈕的值。

https://ember-twiddle.com/3d192704ac6769c7bcc98c93ac9819f9?openFiles=templates.components.my-component.hbs%2Ctemplates.components.my-component.hbs

export default Ember.Component.extend({ 
    buttonText: 'oldValue', 

    actions: { 
    changeValue() { 
     if (this.get('buttonText') === 'newValue') { 
     this.set('buttonText', 'oldValue'); 
     } else { 
     this.set('buttonText', 'newValue'); 
     } 
    } 
    } 
}); 
+0

我怎麼能檢查值,並在其後設置 – Erik

+0

喜埃裏克,我已經更新了代碼示例 – mausinc