javascript - SharePoint javascript 搜索列表
问题描述
列表名称:'FAQ' 列表视图:所有项目 column1:标题 column2:正文 column3:部门
代码假设有两次插入同一个表。第二个 webpart 显示所有条目。第一个是隐藏的,只显示搜索返回的内容。
目前这两个列表都没有显示,也没有结果填充以及 msgHTML 和 newFAQHtml
<style type="text/css">
.ms-listviewtable {display:none;} // hide all listviews on the page by css class
</style>
<script type="text/javascript">
$(document).ready(function() {
$(".ms-listviewtable").eq(1).show(); // show 2nd listview table - Existing Questions/Answers
});
function searchList(){
var list = $(".ms-listviewtable").eq(0); // select 1st listview table - Search Results
var searchInput = $("input[title=ListSearchText]"); // search box text
var listItems = $(".ms-listviewtable:eq(0) tr:not(.ms-viewheadertr)"); // rows of the items in 1st listview table
var results = 0; // search results flag
var searchCol = $("#sfield")[0].selectedIndex; // # of column in list to search - from dropdown
if ( searchInput.val() != "" )
{
var statusDiv = $("#searchStatus"); // div to show status of search
listItems.each(function() // for each item in our list
{
var cellValue = $(this).closest('tr').find('td:eq('+ searchCol + ')').text().toLowerCase(); //get text in cell, convert to lowercase to eliminate case-sensitivity
var row = $(this);
if (cellValue.indexOf( searchInput.val().toLowerCase() ) != -1) // does it match the search text
{
row.show();
results = 1;
}
else
{
row.hide();
}
});
var msgHtml = "<div style='font-size:10pt;color:black;font-weight:normal;margin-left:13px;'><br/>Your search did not return any results.</div>";
var newFAQHtml = "<div style='font-size:10pt;color:black;font-weight:normal;margin-left:13px;'><br/>Did our search return what your'e looking for? If not, you may <a href='javascript:OpenPopUpPage("https://Lists/FAQ/NewForm.aspx");'>enter a new submission</a>.</div>";
if (results > 0)
{
list.show();
list.find('.ms-viewheadertr').show();
statusDiv.html("Search results for: <b>" + searchInput.val() + "</b>");
}
else
{
list.hide();
list.find('.ms-viewheadertr').hide();
statusDiv.html("Search results for: <b>" + searchInput.val() + "</b>" + msgHtml);
}
searchInput.val("");
}
}
</script>
<div onkeydown="javascript:if (event.keyCode == 13) searchList()">
<span style="font-size: 10pt;color:black;font-weight:bold;">Please Select FAQ Category: </span>
<select id="sfield">
<option value=""></option>
<option value="Title">Question</option>
<option value="Body">Category</option>
<option value="Department">Answer</option>
</select>
<input type=”text” id=”sText” title="ListSearchText" />
<input type="button" id="btnSearch" value="Search" onclick="searchList();" />
<a href="https://Help.aspx">Clear Search</a><div>
<br/>
<div id="searchStatus" style="font-size:10pt;font:Tahoma;color:#385b98;width:100%;"></div>
解决方案
推荐阅读
- spring-boot - 如何将闪存消息从控制器调用到百里香模板
- ruby-on-rails - 在哪里可以找到支持 ruby 1.8 的 simplecov 的 gem 包
- flutter - 购物车小部件在颤动中热重新加载时消失
- c++ - Visual Studio 2019 是否可以将文件输出为大写?
- angular - ArcGIS - 错误:编辑时不允许此操作 [可编辑]
- android - 抗锯齿导致recyclerview滞后
- php - 如何在laravel中提交表单之前在模态中添加带有值的附加输入
- node.js - Cors-policy 使用带有查询或参数的 axios get/post 阻止我的请求
- angular - Laravel 5.3 web.php 和 api.php:确保管理员只能访问指定站点部分的正确用法是什么?
- machine-learning - 端到端机器学习项目流程