我有一个在页面上出现两次的联系人列表,我只想在 list/app 第二次出现时向列表中添加一个按钮

I have a list Contacts that appears twice on a page and I only want to add a button to the list in the second occurrence of the list/app

我有一个名为联系人的自定义列表,它在 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;
}

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

尝试:

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