JQuery - 循环遍历员工目录中的员工列表

时间:2015-08-24 21:52:19

标签: jquery

我在xsl页面中嵌入了一个javascript / jquery。 javascript代码遍历sharepoint页面的employee目录中的可用员工列表。当特定字段与值匹配时,将在页面上执行必要操作以显示在顶部。

Below is the code for that:

<xsl:text disable-output-escaping="yes"> 
    <![CDATA[ 
    <!-- JavaScript injected by peoplesearch.xsl. This script waits for the peoplesearch output to render,
         then  -->
          <script type="text/javascript" src="/SiteAssets/jquery-1.11.3.min.js"></script>
          <script type="text/javascript">
    // List of titles held by dept/lab heads. This will be used to
    // identify those heads and move them to the first position in the
    // people list
    var managerTitles = ["A", "B"];

    $(document).ready(function() {
        var personIndex = 0;

        // Iterate each person
        $('.psrch-FullResult').each(function(Index){                
        // Get that person's job title

                var jobTitle = $('#JobTitleField', this).text();

                // If the job title is in the list of managerTitles, make this person the first in the list if
                // they're not aready first
                if($.inArray(jobTitle, managerTitles) >= 0) {
                    // If they're not first in the list, move them there"
                    if(personIndex > 0) {
                        // Move the manager to first
                        $(this).insertBefore($('.psrch-FullResult:first'));
                    }

                    // Insert a block div to create a line break after the manager
                    $("<div style='display:block;clear:both;'></div>").insertAfter($('.psrch-FullResult:first'));
                     //removed this line due to need for multiple heads of a dept -- return false;//Leave the .each iterator
                }

            personIndex++;

    });
    });
    </script> 
    ]]> 
    </xsl:text>

Below is the field declaration in sharepoint 2010


  <xsl:if test="$hasjt">
                      <li id="JobTitleField">
                        <xsl:apply-templates select="hithighlightedproperties/jobtitle" />
                      </li>
                    </xsl:if>


But when I try to fetch the value using the code

var jobTitle = $(&#39;#JobTitleField&#39;,this).text();

它始终仅检索第一个值,并且不会对所有员工进行更改。但循环正在发生完美。任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:0)

使用class然后使用jquery find()..

var jobTitle = $(this).find(li.JobTitleField).text();