其他分享
首页 > 其他分享> > 后台前端

后台前端

作者:互联网

今天在公司是写后台的前端,发现之前写的servlet有一些问题,又逐一修改。也更明白了团队的重要性,首先要有团队意识,合作精神,良好的表达,沟通,协调能力。

   自己做的比较慢,队友就帮忙,共同思考错误。要加油赶上别人的进度呀

   

let pageIndex=1;
let pageSize=4
let baseurl="http://localhost:8080/HTHD002/"
let deleteId=-1;
let slist;
let end=0;

$.ajaxSetup({
async:false
})

$(function () {
initUserData();
getCount();
initPagination();
})

function getCount() {
$.getJSON(baseurl+"/UserServlet",{"type":"getCount"},function(data){
end=Math.ceil(data.data/pageSize)
})
}


//删除
function deleteUser(){
$.getJSON(baseurl+"/UserServlet",{"type":"delete","id":deleteId},function(data){
if(data.code==2){
initUserData();
}else{
alert(data.msg)
}
})
}

//赋值删除ID
function setDeleteId(sid){
deleteId=sid
}

//添加之前的操作
function add(){
let updateForm=document.getElementById('updateForm')
updateForm.id.value='系统默认生成'
updateForm.id.setAttribute('readonly','')
updateForm.password.value=''
updateForm.name.value=''
updateForm.sex.value=''
updateForm.email.value=''
updateForm.telphone.value=''
updateForm.workTime.value=''
updateForm.heduBackground.value=''
updateForm.workNtype.value=''
updateForm.state.value=''
updateForm.date.value='now()'
$("#save").html('添加')
}

//加载分页导航
function initPagination(){
$("#pagination").html(createPaging(end,pageIndex))
}

function changePaging() {
pageIndex=event.target.getAttribute('val')
if (pageIndex) {
initUserData();
initPagination()
}
}

//保存
function save() {
let type='update'
if($("#save").html()=='添加')
type='add'
$.post(baseurl+"/UserServlet?type="+type,$("#updateForm").serialize(),function(data){
if(data.code==2){
initUserData();
}else{
alert(data.msg)
}
},"json")
}

//修改学生信息
function update(sindex) {
let updateForm=document.getElementById('updateForm')
$("#save").html('保存')
updateForm.id.setAttribute('readonly','')
updateForm.id.value=slist[sindex].id
updateForm.password.value=slist[sindex].password
updateForm.name.value=slist[sindex].name
updateForm.sex.value=slist[sindex].sex
updateForm.email.value=slist[sindex].email
updateForm.telphone.value=slist[sindex].telphone
updateForm.workTime.value=slist[sindex].workTime
updateForm.heduBackground.value=slist[sindex].heduBackground
updateForm.workNtype.value=slist[sindex].workNtype
updateForm.state.value=slist[sindex].state
updateForm.date.value=slist[sindex].date

}

 

//查询所有数据
function initUserData() {
$.getJSON(baseurl+"/UserServlet",{"type":"select","pageIndex":pageIndex,"pageSize":pageSize},function (data) {
slist=data.data
let msg = ""
for (let i = 0; i < data.data.length; i++) {
msg += "<tr>";
msg += "<td>" + data.data[i].id + "</td>";
msg += "<td>" + data.data[i].password + "</td>";
msg += "<td>" + data.data[i].name + "</td>";
msg += "<td>" + data.data[i].sex + "</td>";
msg += "<td>" + data.data[i].email + "</td>";
msg += "<td>" + data.data[i].telphone + "</td>";
msg += "<td>" + data.data[i].workTime + "</td>";
msg += "<td>" + data.data[i].heduBackground + "</td>";
msg += "<td>" + data.data[i].workNtype + "</td>";
msg += "<td>" + data.data[i].state + "</td>";
msg += "<td>" + data.data[i].date + "</td>";

msg += "<td>"
msg += " <a href=\"#update\" onclick=\"update("+i+")\" data-toggle=\"modal\"><i class=\"icon-pencil\"></i></a> "
msg += ' <a href="#delete" role="button" onclick="setDeleteId('+data.data[i].id+')" data-toggle="modal"><i class="icon-remove"></i></a> '
msg += "</td>";
msg += "</tr>";
}
$("#stbody").html(msg)
})
}

标签:function,slist,前端,value,msg,updateForm,后台,data
来源: https://www.cnblogs.com/loveJavaJava/p/13583583.html