小编Max*_*ett的帖子

Ruby Koans 评分项目

我正在研究 Ruby Koans,但在弄清楚我编写的方法出了什么问题时遇到了一些麻烦。我在about_scoring_project.rb中,编写了骰子游戏的得分方法:

def score(dice)
  return 0 if dice == []
  sum = 0
  rolls = dice.inject(Hash.new(0)) { |result, element| result[element] += 1; result; }
  rolls.each { |key, value| 
    # special condition for rolls of 1
    if key == 1  
      sum += 1000 | value -= 3 if value >= 3
      sum += 100*value
      next
    end
    sum += 100*key | value -= 3 if value >= 3
    sum += 50*value if key == 5 && value > 0
  }
  return …
Run Code Online (Sandbox Code Playgroud)

ruby

4
推荐指数
2
解决办法
5110
查看次数

在更改Ember路由器中的状态时断开插座/删除视图?

我有一个带有两个出口的应用程序模板的应用程序.当我进入root.index状态时,我只想连接一个插座,当我进入root.chats状态时,我希望连接两个插座.当我从root.index导航到root.chats时这很好用,但是当我向后导航时,navpane出口仍然存在(应该是这样).如何断开此插座或取消首先连接的视图?是否弃用了控制器mixin的disconnectOutlet方法?我应该完全不同地构建这个吗?我在下面提供了我的代码.谢谢.

// State flag helper function. See https://github.com/ghempton/ember-router-example/blob/master/js/app.js

function stateFlag(name) {
  return Ember.computed(function() {
    var state = App.router.currentState;
    while(state) {
      if(state.name === name) return true;
      state = state.get('parentState');
    }
    return false;
  }).property('App.router.currentState');
}

// Application

App = Em.Application.create({

    ApplicationController: Ember.Controller.extend({
        isChats: stateFlag('chats')
    }),
    ApplicationView: Ember.View.extend({
        templateName: 'application'
    }),
    ChatlistController:  Em.Controller.extend({
        hideView: false
    }),
    ChatlistView:  Em.View.extend({
        templateName:  'chatlist',
        didInsertElement: function(){
            this.$("#nav_pane").css({'left':'-=275', 'z-index':'-5'}).animate({
                left: ["+=275", 'swing'],
            },500,function() {
                $(this).css('z-index','5')
            });
        },
        _hideViewChanged: function() {
            if (this.get('hideView')) {
                this.hide();
            }
        }.observes('hideView'),
        hide: function() …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-old-router

3
推荐指数
1
解决办法
4679
查看次数

标签 统计

ember-old-router ×1

ember.js ×1

ruby ×1