小编kdu*_*bss的帖子

Write a function "groupBy(array, callback)"

I have a JavaScript task where I have to implement a function "groupBy", which, when given an array of objects and a function, returns an object where the input objects are keyed by the result of calling the fn on each of them.

Essentially, I have to write a function, "groupBy(array, callback)", returns an object where the following is returned.

For example:

  var list = [{id: "102", name: "Alice"},
              {id: "205", name: "Bob", title: "Dr."},
              {id: "592", name: "Clyde", …
Run Code Online (Sandbox Code Playgroud)

javascript callback

5
推荐指数
2
解决办法
631
查看次数

使用 f.select 通过 grouped_options_for_select 设置默认值

我有一个由以下内容呈现的分组下拉菜单,

= f.select :location_id, 
           grouped_options_for_select(grouped_location_options, 
                                      default_location_name), 
           { selected: default_location_name }, 
           class: 'form-control'
Run Code Online (Sandbox Code Playgroud)

我希望将默认值设置为Unassigned,但上面的代码似乎没有执行我想要的操作。

有人可以给我一些线索来解决这个问题吗?

提前谢谢了!

ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

5
推荐指数
1
解决办法
1008
查看次数