`
hbhgjiangkun
  • 浏览: 95630 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

最近的一段JS中得到的启示

 
阅读更多

以前写脚本文件可能是其他的方式,通过这段js我想到了其他一些东西

var Participant = function(){
this.entityId = null;
this.entityName = null;
this.entityType = null;
this.params = "";
}
var participants = new Array();
function addParticipant(node,checked){
if(checked&&(isHave(node)==-1)){
//增加
var p = new Participant();
p.entityId=node.id;
p.entityName=node.name;
p.entityType=node.entityType;
participants.push(p);
}else{
//删除
var index = isHave(node);
if(index!=-1){
participants.splice(index,1);
}
}
//重新将值设置到textarea中
addData();
}
function addExtParticipant(node){
var index = isHaveExt(node);
var p = new Participant();
p.entityId=node.id;
p.entityName=node.name;
p.entityType=node.entityType;
p.params = node.params;
if(index==-1){
participants.push(p);
}else{
participants.splice(index,1,p);
}
addData();
}
function addData(){
var str = null;
for(var i=0;i<participants.length;i++){
if(str==null){
str = participants[i].entityName;
}else{
str = str+";"+participants[i].entityName;
}
}
document.getElementById("actors").value=(str==null?"":str);
}
//如果存在则返回位置index,否则返回-1
function isHave(node){
if(node){
for(var i=0;i<participants.length;i++){
if(participants[i].entityId==node.id){
return i;
}
}
}
return -1;
}
function isHaveExt(node){
if(node){
for(var i=0;i<participants.length;i++){
if(participants[i].entityType==node.entityType){
return i;
}
}
}
return -1;
}
$(function(){
$('.easyui-tabs').tabs({
/*tools:[{
iconCls:'icon-add',
handler: function(){
art.dialog.close();
}
},{
iconCls:'icon-save',
handler: function(){
art.dialog.parent.addDataToTable(participants);
art.dialog.close();
}
}]*/
});
$("div[url]").panel({
onBeforeOpen:function(){
var p = this;
if($(p).find("iframe:first").attr("src")==""){
$(p).find("iframe:first").attr("src",p.url);
}
}
});
});

function save_onclick(){
art.dialog.parent.addDataToTable(participants);
art.dialog.close();
}

function cancle_onclick(){
art.dialog.close();
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics