我有一个列表联系人,它在页面上出现两次,我只想在第二次出现列表/应用程序时向列表中添加按钮

问题描述 投票:0回答:1

我有一个名为通讯录的自定义列表,该列表两次出现在WIKI页面上(彼此相邻)。在第一个实例(左侧)上将是具有超链接到RACI页面的联系人列表。在第二个实例(右侧)上,我有一个可能包含两个联系人的列表,这些视图是视图的结果,该视图将显示支持联系人的列表。

我开发的脚本将找到联系人列表,并添加一个按钮以将电子邮件发送给适用的联系人。同样的脚本也会将按钮添加到第一个实例。我只希望我的脚本影响第二个实例。

我的脚本是:

var subjectType="";
var bodyText="";
$(document).ready(function() {  

    // Get the subject type
    var this_js_script = $('script[src*=AddContactButtons]');
    subjectType = this_js_script.attr('data-Subject'); 
    if (typeof subjectType == 'undefined' || subjectType == null || subjectType == ''){
      subjectType = "Site";
    }
    //console.log('subjectType='+subjectType);
    buttonLabel = this_js_script.attr('data-Button'); 
    if (typeof buttonLabel == 'undefined' || buttonLabel == null || buttonLabel == ''){
      buttonLabel = "Help";
    }
    //console.log('buttonLabel='+buttonLabel);
    bodyText = this_js_script.attr('data-BodyText'); 
    if (typeof bodyText == 'undefined' || bodyText == null || bodyText == ''){
      bodyText = "";
    }
    //console.log('bodyText='+bodyText);
    buttoncolor = this_js_script.attr('data-ButtonColor'); 
    if (typeof buttoncolor == 'undefined' || buttoncolor == null || buttoncolor == ''){
      buttoncolor = "#004d99";
    }
    //console.log('buttoncolor='+buttoncolor);
    buttontextcolor = this_js_script.attr('data-ButtonTextColor'); 
    if (typeof buttontextcolor == 'undefined' || buttontextcolor == null || buttontextcolor == ''){
      buttontextcolor = "white";
    }
    //console.log('buttontextcolor='+buttontextcolor);
    addContactButtons(subjectType,bodyText,buttoncolor,buttontextcolor);
});
function addContactButtons(subjectType,bodyText,buttoncolor,buttontextcolor){
    var listTitle="Contacts";
    //console.log('addcontactButtons:subjectType='+subjectType);
    //console.log('addcontactButtons:bodyText='+bodyText);
    //console.log('addcontactButtons:buttoncolor='+buttoncolor);
    $("table.ms-listviewtable[summary='"+listTitle+"']>tbody>tr").each(function(){
        $(this).append("<input type='button' value='"+buttonLabel+"' style='background-color:"+buttoncolor+"; color:"+buttontextcolor+"' class='btnSub' onclick='javascript:openMail(this);'>");
    });
}
function openMail(btn){
    var emailString = "mailto:";
    var emailID = $(btn).prev("td").text()
    var URL = _spPageContextInfo.webServerRelativeUrl;
    //console.log('openMail:subjectType='+subjectType);
    //console.log('openMail:bodyText='+bodyText);
    //console.log('openMail:URL='+URL);

    emailString += emailID ;
    if (subjectType == 'Site'){
        emailString += "?Subject=SharePoint Site Support - Site=";
        //emailString += _spPageContextInfo.webServerRelativeUrl;
    } else {
        emailString += "?Subject="+subjectType;
    }
    if (bodyText != ''){
        emailString += "&Body="+bodyText;
    }
    var finalEmailString = emailString.replace(/Site=/,"Site="+URL);
    //console.log(finalEmailString);
    location.href=finalEmailString;
}

如何将脚本的范围限制为仅应用程序部件的第二个实例?

javascript sharepoint-2013
1个回答
0
投票
$("tbody>tr","table.ms-listviewtable[summary='MyList']:eq(1)").each(function () { $(this).append("<input type='button' value='value' class='btnSub' onclick='javascript:openMail(this);'/>"); });

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.