簡體   English   中英

在Ember View中處理點擊事件

[英]Handling a click event in an Ember View

單擊下面的鏈接時,我想使ol元素展開。 我知道如何在單擊ol本身時使其擴展。

App.MemberListingView = Ember.View.extend({
  isExpanded: false,
  classNameBindings: ['isExpanded'],
  click: function() {
    return this.toggleProperty('isExpanded');
  }
});

模板:

{{#view 'App.MemberListingView'}}
    <ol class="member-listing">
        {{#each}}
          {{user-card user=this}}
        {{/each}}
    </ol>
    <a href="#">Click here to see all</a>
{{/view}}

我希望錨元素是單擊觸發器,而不是ol本身。 我該怎么做呢? 我必須為鏈接編寫一個單獨的視圖嗎?

我對Ember還是很陌生,但這應該可行-

{{#view 'App.MemberListingView'}}
    <ol class="member-listing">
        {{#each}}
          {{user-card user=this}}
        {{/each}}
    </ol>
    <a href="#" {{action 'expandIt' target='view'}}>Click here to see all</a>
{{/view}}

在您看來(或控制器)-

App.MemberListingController = Ember.Controller.extend({
  isExpanded: false,
  classNameBindings: ['isExpanded'],
  actions: {
    expandIt: function() {
        return this.toggleProperty('isExpanded');
    }
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM