问题描述
如何使用处理使用Javascript动态生成的字段,例如或使用?我已经尝试在嵌套字段中明确地包含js文件,但没有运气:
How can I get garlic.js to work on fields generated dynamically with Javascript, for instance like in this Railscast or by using Cocoon? I have tried explicitly including the js file in the nested fields partial, but no luck:
= javascript_include_tag 'garlic'
.nested-fields
= f.inputs do
= f.input :client_id #etc
推荐答案
我如何使用jquery存储api:除了调用大蒜以保存表单状态外,还要保留动态生成表单的HTML。
How I got around this was using the jquery storage api: https://github.com/julien-maurel/jQuery-Storage-API to persist the HTML of the dynamically generated form in addition to invoking garlic to save the form state.
页面加载后,我会检查localstorage中是否存在持久化表单。如果是,则将html加载到表单元素中,然后调用garlic恢复表单状态!
Upon page load, I check if the persisted form exists in localstorage. If it does, then load the html into the form element, then call garlic to restore form state!
这篇关于Garlic.js动态生成的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!