如何根据匹配变量的数据属性select一个div?

how to select a div based on the data attribute that matches a variable?

我正在尝试将 Jquery ui 选项卡与 salesforce 社区一起使用,如果根据前一页的项目 ID 将用户从不同的页面定向到当前页面,当前页面需要突出显示相应的选项卡。

These tabs are generated based on how many project a user has which prevents me from giving them an ID inside the html

<script>
  $(document).ready(function(){
    var focusedProject = '{!focusedProjectId}';
    $('.projectTabs').each(function(){
       var id = $(this).data('salesforceprojectid');
       if(focusedProject === id){
         $('*[data-salesforceprojectid="HARD CODED ID"]').addClass('ui-state-active');
       }
    });
  });
</script>

你在哪里看到 硬编码 ID 我想把变量 focusedProject - 这似乎不可能,有没有人知道这个的替代解决方案?

<ul>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
</ul>

你做不到

$('*[data-salesforceprojectid="' + focusedProject  + '"]').addClass('ui-state-active');

将硬编码部分变成变量?