在 .each for 循环中选择 rest_in_place

Posted

技术标签:

【中文标题】在 .each for 循环中选择 rest_in_place【英文标题】:rest_in_place select within a .each for loop 【发布时间】:2013-06-02 22:12:18 【问题描述】:

我在 Rails 3 中使用 rest_in_place gem 在返回模型结果的表中执行就地编辑。

对于编辑文本输入,我没有遇到任何问题。对于我的<td> 字段之一,我希望该字段在单击以进行编辑时,具有从系统内具有用户的用户模型填充的选择下拉框。

我尝试在我的模型中使用以下代码,但似乎 rest_in_place 期望此元素位于表单中。

html

<td style="font-size: 10px;"><span class="rest-in-place" data-select="AbaseUser" data-formtype="select" data-object="marketer_import" data-attribute="new_user" data-url="<%= "/marketer_imports/#marketer_import.id" %>">
  <%= marketer_import.new_username unless marketer_import.new_username.nil? %>
</span></td>

javascript

RestInPlaceEditor.prototype.bindForm = function() 
  this.activateForm = RestInPlaceEditor.forms[this.formType].activateForm;
  return this.getValue = RestInPlaceEditor.forms[this.formType].getValue;
;

我在 Chrome 控制台中收到以下错误

Uncaught TypeError: Cannot read property 'activateForm' of undefined

【问题讨论】:

【参考方案1】:

我可以看到here,rest_in_place 默认不支持“选择”表单类型(仅输入和文本区域)。考虑改用best_in_place。 Ryan Bates 提供了一个很好的教程here。

【讨论】:

以上是关于在 .each for 循环中选择 rest_in_place的主要内容,如果未能解决你的问题,请参考以下文章

浅谈for each循环

jquery中使用each()和for循环哪个好些

jquery $.each 和for怎么跳出循环终止本次循环

从字节码看Java中for-each循环(增强for循环)实现原理

你如何在 EJS 中执行 for 循环/for each?

使用 terraform 在 for_each 嵌套资源中循环