jquery排序与动态添加option以及属性

function getOrgansid() {
url="<%=basePath%>/rest/bsc/organ/selectOrganSidAllList";
$.ajax({
type:"POST",
url:url,
dataType:"json",
contentType: "application/json; charset=utf-8",
// data:,
success:function (data) {

if(data.res>0){
var $domOptions=data.data;
$domOptions.sort(function(a,b){return a.sid-b.sid});//排序
$.each($domOptions,function(n,value){
 $.each($domOptions,function(n,value){
// $("#se_organObject").append("<option sid="+value.sid+" value="+n+">"+value.organName+"</option>");//添加option
// $("#se_organObject").append($("<option></option>"));//添加option
$("#se_organObject").append($("<option>"));//添加option
$("#se_organObject option:eq("+n+")").attr("sid",value.sid);
$("#se_organObject option:eq("+n+")").attr("value",value.organName);
$("#se_organObject option:eq("+n+")").text(value.organName);
}
);

}
);
}else{
layer.msg("数据获取失败!",{offset:"100px"});
}
sid=[];
contentItem=[];
PeriodData=[];
PeriodData1={};
json={};
}
});

}


var organSid = $("#se_organObject option:selected").attr("sid");
alert(organSid);
if (typeof(organSid) === "undefined"){
organSid=10;
}
posted @ 2018-05-30 12:25  wlhebut  阅读(234)  评论(0编辑  收藏  举报