<div class="panel-body">
<ol class="list-group col-sm-9" id="rule-detail">
<div class="list-group-item h">规则:</div>
<li class="list-group-item h active list-rule-item" id="expression" data-toggle="tooltip" title="点击可编辑哦">年龄 包含 [18,55]</li>
<li class="list-group-item h list-rule-item" id="">姓名 包含 [18,55]</li>
<li class="list-group-item h list-rule-item" id="">姓名1 包含 [18,55]</li>
<li class="list-group-item h list-rule-item" id="">姓名2 包含 [18,55]</li>
<li class="list-group-item h list-rule-item" id="">姓名3 包含 [18,55]</li>
</ol>
<div class="col-sm-12">
<label class="col-sm-4"> </label>
<div class="col-sm-12 text-center">
<button type="button" data-dismiss="modal" class="btn btn-default" id="save_final">保存最终规则</button>
</div>
</div>
</div>
js代码
document.getElementById('save_final').addEventListener('click', seveFinalRule, false);
function seveFinalRule(obj) {
var ali = $('#rule-detail li');
var arr = [];
var obj={};
obj.data=[];
for (var i = 0; i < ali.length; i++) {
obj.data[i]={};
arr.push((function (n) {
obj.data[n].index=n+1;
obj.data[n].name=ali[n].innerText;
})(i));
}
console.log(obj);
Ajax({
url: '/risk-admin/rule_node/edit_rule_node',
data: {
data:obj
},
success: function(opt, res) {
console.log(res.msg);
},
error: function(opt, err) {
console.log("接口报错了!")
}
});
}
最后输出的obj
Object
data
:
Array[5]
0
:
Object
index
:
1
name
:
"年龄 包含 [18,55]"
__proto__
:
Object
1
:
Object
index
:
2
name
:
"姓名 包含 [18,55]"
__proto__
:
Object
2
:
Object
index
:
3
name
:
"姓名1 包含 [18,55]"
__proto__
:
Object
3
:
Object
4
:
Object
index
:
5
name
:
"姓名3 包含 [18,55]"
__proto__
:
Object
length
:
5
__proto__
:
Array[0]
__proto__
:
Object