jQuery Repeater代码,如果我要添加多个组并使用setList函数,则它总是为最后一组而不是所有组设置字段值。
例如;
<form class="repeater">
<div data-repeater-list="group-a">
<div data-repeater-item>
<input type="text" name="input-field-name-1" value=""/>
<input type="text" name="input-field-name-2" value=""/>
<input data-repeater-delete type="button" value="Delete"/>
</div>
</div>
<input data-repeater-create type="button" value="Add"/>
</form>
<form class="repeater">
<div data-repeater-list="group-b">
<div data-repeater-item>
<input type="text" name="input-field-name-1" value=""/>
<input type="text" name="input-field-name-2" value=""/>
<input data-repeater-delete type="button" value="Delete"/>
</div>
</div>
<input data-repeater-create type="button" value="Add"/>
</form>
<script>
var myJson = '{"group-a":[{"input-field-name-1":"Apple","input-field-name-2":"5"}], "group-b":[{"input-field-name-1":"Mango","input-field-name-2":"10"}]}';
var myObj = JSON.parse(myJson);
var $repeater = $(".repeater").repeater();
$repeater.setList(myObj["group-a"]);
$repeater.setList(myObj["group-b"]);
</script>
我想为多个组设置所有转发器组(如组a,组b,每个组都基于setList JSON逐组设置字段值),并多次设置(获取/设置为JSON格式)。 >
图书馆:
https://github.com/DubFriend/jquery.repeater
一些参考:
https://github.com/DubFriend/jquery.repeater/issues/46#issuecomment-280854544