码迷,mamicode.com
首页 > 其他好文 > 详细

页面视图中的按钮操作指向

时间:2015-01-20 13:20:08      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

页面模板中的操作交互按钮,默认指向该模板对应的控制器。当然也可以指向相对应的路由和视图,只需要在这些类里面定义该操作处理函数即可,例如

{{#if isExpanded}}
  <div class=body>{{body}}</div>
  <button {{action contract}}>Contract</button>
{{else}}
  <button {{action expand}}>Show More...</button>
{{/if}}

App.PostController = Ember.ObjectController.extend({
  // initial value
  isExpanded: false,

  actions: {
    expand: function() {
      this.set(isExpanded‘, true);
    },

    contract: function() {
      this.set(isExpanded‘, false);
    }
  }
});

App.PostRoute = Ember.Route.extend({
  actions: {
    expand: function() {
      this.controller.set(isExpanded‘, true);
    },

    contract: function() {
      this.controller.set(isExpanded‘, false);
    }
  }
});

App.PostsIndexView = Ember.View.extend({
  actions: {
    select: function(post) {
      // do your business.
    }
  }
});
 
 
 

页面视图中的按钮操作指向

标签:

原文地址:http://www.cnblogs.com/toward-the-sun/p/4235702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!