<div class="forms-container">
<div class="form-template">
First Name <input>
.. a lot of other data ...
Last Name <input>
<div>
<button onclick="add_another();">Add another!</button>
<div>
现在,JavaScript:
function add_another(){
jQuery(".form-template").clone().appendTo(".forms-container");
}
由于 jQuery主要处理 DOM Elements,因此 也许不会是做这项工作的合适工具。Immutable.js是由 Facebook创建的 56 kb (minified)库。
// roughly implementing
import Immutable from 'immutable'
//
const oldObj = { foo: 'bar', bar: 'baz' }
// create a map from the oldObj and then convert it to JS Object
const newObj = Immutable.Map(oldObj).toJS()