- 注册时间
- 2017-8-4
- 最后登录
- 2024-9-13
- 阅读权限
- 10
- 积分
- 353
- 精华
- 0
- 帖子
- 30
|
如图所示,表单是动态添加上去的,点击保存按钮获取表单中的值,怎样组合成一个数组对象传到后台。然后再试打开的话把上次保存的值回显到表单里,如何进行遍历设置值。
- function addItemHtml(index, item) {
- if(!index) {
- index = 1;
- }
- var htmlStr = '<div class="card" id="card_'+ index +'">' +
- '<div class="card-header"><h3 class="card-title">候选名称'+ index +'</h3><a class="card-btn-del" href="javascript:void(0)" onclick="delElement(\'card_\' + \''+index+'\')">删除</a></div>' +
- '<div class="card-body">' +
- '<div class="form-item">' +
- '<div class="form-block">' +
- '<label class="form-label"><span class="required-tip">*</span>分所中文名称:</label>' +
- '<div class="form-input">' +
- '<input class="mini-textbox" id="branchFirmName_' + index +'" name="name" emptyText="请输入分所中文名称" errorMode="border" required requiredErrorText="分所中文名称不能为空">' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<div class="form-item">' +
- '<div class="form-block">' +
- '<label class="form-label"><span class="required-tip">*</span>分所中文简称:</label>' +
- '<div class="form-input">' +
- '<input class="mini-textbox" id="branchFirmShortName_'+ index +'" name="shortName" emptyText="请输入分所中文简称" errorMode="border" required requiredErrorText="分所中文简称不能为空" onValuechanged="methods.onNameValueChanged(e, \'branchFirmShortPinyin_\' + \''+index+'\')">' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<div class="form-item">' +
- '<div class="form-block">' +
- '<label class="form-label"><span class="required-tip">*</span>分所英文名称:</label>' +
- '<div class="form-input">' +
- '<input class="mini-textbox" id="branchFirmEnglishName_'+ index +'" name="engilshName" emptyText="请输入分所英文名称" vtype="isEnglish" errorMode="border" required requiredErrorText="分所英文名称不能为空">' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<div class="form-item">' +
- '<div class="form-block">' +
- '<label class="form-label"><span class="required-tip">*</span>分所简称拼音:</label>' +
- '<div class="form-input">' +
- '<input class="mini-textbox" id="branchFirmShortPinyin_'+ index +'" name="pinYin" emptyText="请输入分所简称拼音" errorMode="border" required requiredErrorText="分所简称拼音不能为空">' +
- '</div>' +
- '</div>' +
- '</div>' +
- '</div>' +
- '</div>';
- return htmlStr;
- }
- function addRow(eleId) {
- var count = $("#" + eleId).find(".card").length;
- count = count + 1;
- if(count > maxCount){
- mini.alert("候选名称最多添加10条");
- return;
- }
- var htmlStr = addItemHtml(count);
- $("#" + eleId).append(htmlStr);
- mini.parse(htmlStr);
- }
- function delElement(eleId) {
- var num = $("#shortList").find(".card").length;
- if(num < 6){
- mini.alert("至少保留5条");
- return;
- }
- mini.showMessageBox({
- title: "提示",
- message: "确定要删除该条记录吗?",
- buttons: ["ok", "cancel"],
- iconCls: "mini-messagebox-question",
- callback: function(action){
- if(action == "ok"){
- $("#" + eleId).remove();
- for (var i = 0; i <= num; i++) {
- $("#shortList .card").eq(i).find(".card-title").html("候选名称" + (i + 1));
- }
- }
- }
- })
- }
- function getItemsData() {
- var arr = [];
- $("#shortList").find(".card").each(function () {
- var _id = $(this).attr("id");
- var obj = new Object();
- var controls = mini.getChildControls(_id);
- for(var i = 0; i < controls.length; i++){
- var control = controls[i];
- obj[control.name] = control.value;
- }
- arr.push(obj);
- });
- return arr;
- }
复制代码
|
|