后台查询结果 PDFSearchResult实体类:

  [DataContract(Name = "PDFSearchResult")]
public class PDFSearchResult
{ public PDFSearchResult(string title, string fileUrl)
{
Title = title;
FileUrl = fileUrl;
} [DataMember(Name = "title")]
public string Title { get; set; } [DataMember(Name = "fileUrl")]
public string FileUrl { get; set; } }

另外,有一个PagedResult泛型类,PagedResult<T>

  [DataContract(Name = "pagedCollection", Namespace = "")]
public class PagedResult<T>
{
public PagedResult(long totalItems, long pageNumber, long pageSize); [DataMember(Name = "items")]
public IEnumerable<T> Items { get; set; }
[DataMember(Name = "pageNumber")]
public long PageNumber { get; }
[DataMember(Name = "pageSize")]
public long PageSize { get; }
[DataMember(Name = "totalItems")]
public long TotalItems { get; }
[DataMember(Name = "totalPages")]
public long TotalPages { get; } //
// Summary:
// Calculates the skip size based on the paged parameters specified
//
// Remarks:
// Returns 0 if the page number or page size is zero
public int GetSkipSize();
}

后台,采用Web Api (/api/SearchApi/GetPDFSearchResults/), 返回值类型为 PagedResult<PDFSearchResult>, 是Json类型返回值

在页面表现UI层,有两个tab,左边的tab显示的是页面的搜索结果searchResult, 右边的tab显示的是pdf文件的搜索结果PDFSearchResult

页面SearchResult.cshtml如下:

<section id="searchListing" class="row search">
<div> <div class="tabs">
<ul class="tab">
<li data-ui="tab-nav"><a href="#">Web Page Results</a></li>
<li data-ui="tab-nav"><a href="#">PDF Results</a></li>
</ul>
</div>
<div class="tabContent">
<div id="resultsArea" class="search-results" style="display:block;" data-ui="tab-content">
<div id="NoResultsMessage" style="display:none;">
<p class="results-title">No Results For<strong class="search-term"></strong>'</p>
</div>
<div id="HasResultsMessage" style="display:none;">
<p class="results-title">Search Results For<strong class="search-term"></strong>'</p>
</div>
<div class="results" id="SearchResultsContainer">
<article class="row">
<a href="#">
<div>
<h2></h2>
<p></p> <p class="link">Read more</p>
</div>
</a>
</article>
</div>
<ul class="pagination">
<li><a href="#" class="prev"><i class="gi icon-arrow"></i></a></li>
<li class="page"><a href="#"></a></li>
<li><a href="#" class="next"><i class="gi icon-arrow"></i></a></li>
</ul>
</div>
<div id="PDFResultArea" class="search-results" style="display:none;" data-ui="tab-content">
<div id="NoPDFResultsMessage" style="display:none;">
<p class="results-title">No Results For<strong class="search-term"></strong>'</p>
</div>
<div id="HasPDFResultsMessage" style="display:none;">
<p class="results-title">Search Results For<strong class="search-term"></strong>'</p>
</div>
<div class="results" id="SearchPDFResultsContainer">
<article class="row">
<a href="#"> </a>
</article>
</div>
<ul class="pagination">
<li><a href="#" class="prev"><i class="gi icon-arrow"></i></a></li>
<li class="page"><a href="#"></a></li>
<li><a href="#" class="next"><i class="gi icon-arrow"></i></a></li>
</ul> </div>
</div>
</div>
</section>

这里,在页面展示上,应该看上去如下图:

为了在同一个页面,也就是SearchResult.cshtml中实现这个tab功能,我用JQuery写了个tab功能,如下

tab.js

function tabs(state,control,show){

    $(control + "> li").on(state, function(){

        $(this).addClass("on").siblings().removeClass("on");

        var index = $(this).index();

        $(show + "> div").eq(index).show().siblings().hide();
}) $(control + "> li").eq(0).attr("class", "on");
$(show + "> div").eq(0).show();
} tabs("click", ".tab", ".tabContent");

The css style 如下

.tabs {
position: relative;
margin-top: 60px;
margin-bottom: 20px; }
.tabs > ul {
list-style: none;
border-bottom: 1px solid #c0c0c0;
margin-top:;
padding:; }
.tabs > ul > li {
float: left;
margin-bottom: -1px; }
[dir="rtl"] .tabs > ul > li {
float: right; }
.tabs > ul > li a {
display: block;
line-height:;
margin-right: .2rem;
padding: 0 1rem;
border: 1px solid transparent;
text-decoration: none;
cursor: pointer; }
[dir="rtl"] .tabs > ul > li a {
margin-right:;
margin-left: .2rem; }
.tabs > ul > li a:hover {
background: #fff !important;
border: 1px solid #fff !important;
color: #ff7900; }
.tabs > ul > li > [aria-selected="true"], .tabs > ul > li > [aria-selected="true"]:hover {
background: red !important; }
.tabs > ul li.on {
background-color: #fff;
border: 1px solid #c0c0c0;
border-bottom-color: transparent;
color: #454545;
cursor: default; }
.tabs > ul li.on a {
color: #ff7900; }
.tabs > * {
display: none; }
.tabs > ul,
.tabs [tabIndex="0"] {
display: block; }

然后,我写了一个Jquery Plugin来实现PDFSearchResult的展示功能,也就是说JSON结果,展示到SearchResult.cshtml页面上

在这个Jquery plugin中,调用ajax来调用web api (/api/SearchApi/GetPDFSearchResults/),返回json结果,展现到web页面上

view.pdfsearch.js

(function ($) {

    $.fn.PDFSearch = function (options) {

        return this.each(function () {

            var pdfSearch = $(this);

            pdfSearch.pdfResultArea = pdfSearch.find("#PDFResultArea");

            pdfSearch.noPDFResultMessage = pdfSearch.pdfResultArea.find("#NoPDFResultsMessage");
pdfSearch.hasPDFResultMessage = pdfSearch.pdfResultArea.find("#HasPDFResultsMessage");
pdfSearch.PDFResultContainer = pdfSearch.pdfResultArea.find("#SearchPDFResultsContainer"); pdfSearch.searchPDFResultTemplate = pdfSearch.PDFResultContainer.find("article").clone(); pdfSearch.queryField = $("input[name='search']"); pdfSearch.searchTermLabel = $(".search-term"); pdfSearch.oldTerm = undefined;
pdfSearch.term = pdfSearch.queryField.val(); //Paging elements
pdfSearch.paginationWrapper = pdfSearch.pdfResultArea.find('ul.pagination');
pdfSearch.pageTemplate = pdfSearch.paginationWrapper.find('.page').clone();
pdfSearch.pagePrevious = pdfSearch.paginationWrapper.find('.prev');
pdfSearch.pageNext = pdfSearch.paginationWrapper.find('.next'); // Page tracking
pdfSearch.pageSize = 10;
pdfSearch.pageNumber = 1;
pdfSearch.totalPages = 0; // Sets up pagination for search results.
pdfSearch.paginate = function (data) { pdfSearch.totalPages = data.totalPages;
pdfSearch.paginationWrapper.find('.page').remove();
if (pdfSearch.totalPages > 1) {
pdfSearch.pagePrevious.toggle(data.pageNumber > 1);
pdfSearch.pageNext.toggle(data.pageNumber < pdfSearch.totalPages); for (i = 1; i < pdfSearch.totalPages + 1; i++) {
var page = pdfSearch.pageTemplate.clone();
var link = page.find('a');
if (i == data.pageNumber)
page.addClass('active');
page.data('page', i);
link.text(i); pdfSearch.pageNext.parent().before(page).before('\n\r');
} pdfSearch.paginationWrapper.show(0);
} else {
pdfSearch.paginationWrapper.hide(0);
}
} pdfSearch.previous = function (evt) {
return pdfSearch.goToPage(evt, pdfSearch.pageNumber - 1);
} pdfSearch.next = function (evt) {
return pdfSearch.goToPage(evt, pdfSearch.pageNumber + 1);
} pdfSearch.goToPage = function (evt, pageNumber) {
pdfSearch.pageNumber = pageNumber || $(this).data('page');
if (pdfSearch.pageNumber > pdfSearch.totalPages) pdfSearch.pageNumber = pdfSearch.totalPages - 1;
if (pdfSearch.pageNumber < 1) pdfSearch.pageNumber = 1; pdfSearch.searchPDF();
return false;
} // filter change handler
pdfSearch.handleQuery = function (evt) { pdfSearch.term = $(this).val();
if (pdfSearch.oldTerm != pdfSearch.term) {
pdfSearch.oldTerm = pdfSearch.term;
pdfSearch.searchPDF();
}
return false;
} pdfSearch.searchPDF = function () {
pdfSearch.pdfResultArea.addClass("loading"); $.ajax({
type: "GET",
url: "/umbraco/api/SearchApi/GetPDFSearchResults/",
dataType: "json",
data: {
filter: pdfSearch.term,
pageNumber: pdfSearch.pageNumber,
pageSize: pdfSearch.pageSize
},
success: function (data) {
pdfSearch.searchTermLabel.text(pdfSearch.term);
pdfSearch.noPDFResultMessage.hide();
pdfSearch.hasPDFResultMessage.hide();
pdfSearch.paginate(data);
pdfSearch.PDFResultContainer.empty(); if (!data.items || data.items.length == 0) {
pdfSearch.noPDFResultMessage.show();
}
else {
// Binding search result to UI
for (var i = 0; i < data.items.length; i++) {
var pdfResult = data.items[i];
var PdfResultTemplate = pdfSearch.searchPDFResultTemplate.clone(); _populatePDFContent(pdfResult, PdfResultTemplate); pdfSearch.PDFResultContainer.append(PdfResultTemplate);
}
pdfSearch.hasPDFResultMessage.show();
}
},
complete: function () {
pdfSearch.searchTermLabel.text(pdfSearch.term);
pdfSearch.pdfResultArea.removeClass("loading");
}
});
}; _populatePDFContent = function (result, template) { var pdfLinkElem = $(template.find("a"));
pdfLinkElem.attr("href", result.fileUrl);
pdfLinkElem.attr("target", "_blank");
pdfLinkElem.html(result.title); }; pdfSearch.queryField.on("keyup", pdfSearch.handleQuery); // Setup pagination triggers.
pdfSearch.pagePrevious.on("click", pdfSearch.previous);
pdfSearch.pageNext.on("click", pdfSearch.next); // Bind to all future page clicks.
pdfSearch.paginationWrapper.on('click', 'li.page', pdfSearch.goToPage); pdfSearch.searchPDF(); });
}
}(jQuery)); $(function () {
$('section.search').PDFSearch(); });

自己在项目中写的一个Jquery插件和Jquery tab 功能的更多相关文章

  1. 【Filter 不登陆无法访问】web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面的功能

    在web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面,而重定向到登陆界面的功能. 项目是用springMVC+spring+hibernate实现 (和这个没有多大关系) 第一步: 首先 ...

  2. Web 项目中分享到微博、QQ空间等分享功能

    Web 项目中分享到微博.QQ空间等分享功能 网上有很多的模板以及代码,但是有很多都不能分享内容,简单的测试了下: 以新浪微博为例,文本框中的内容是title属性,下面的链接是url属性,如果你的链接 ...

  3. C# winform项目中ListView控件使用CheckBoxes属性实现单选功能

    C# winform项目中ListView控件使用CheckBoxes属性实现单选功能 在做项目时需要使用ListView控件的CheckBoxes属性显示,还要在点击行时自动选中CheckBoxes ...

  4. 解决:一个项目中写多个包含main函数的源文件并分别调试运行

    自己在学c++的时候,一个项目中的多个cpp文件默认不允许多个main函数的出现,但是通过选项操作能够指定单个cpp文件进行运行,如下: 1.此时我就想运行第二个cpp文件,我们只需要把其他的两个右键 ...

  5. 在类库或winform项目中打开另一个winform项目的窗体

    假设类库或winform项目为A,另一个winform项目为B.那麽在A中添加一个接口,里面有一个Show方法,然后在B中写一个类b继承这个接口,并重写这个方法,具体内容为弹出某个窗体.然后在A中另一 ...

  6. 在angular项目中使用bootstrap的tooltip插件时,报错Property 'tooltip' does no t exist on type 'JQuery<HTMLElement>的解决方法和过程

    在angular4的项目中需要使用bootstrap的tooltip插件. 1. 使用命令安装jQuery和bootstrap npm install bootstrap jquery --save ...

  7. Laravel 项目中编写第一个 Vue 组件

    和 CSS 框架一样,Laravel 不强制你使用什么 JavaScript 客户端框架,但是开箱对 Vue.js 提供了良好的支持,如果你更熟悉 React 的话,也可以将默认的脚手架代码替换成 R ...

  8. MES项目中出现的一个事务嵌套的使用场景

    昨天在MES项目中,需要在业务逻辑的几个关键点记录错误信息,需要把错误信息写入数据表. 但是由于整个业务逻辑都是包在一个事务模板里面的 比如这样的: WhhTransactionTemplate tr ...

  9. 【Atom】在一个中/大型项目中,那些好用而强大的atom功能

      作为一个学生党,一开始使用atom时候并没有意识到atom一些小功能的巨大作用,直到自己实习参与了项目,才知道这些功能在一个项目中是能极大提高工作效率的开发利器   下面是一位不愿意透露其姓名的彭 ...

随机推荐

  1. 【BZOJ3611】[Heoi2014]大工程 欧拉序+ST表+单调栈

    [BZOJ3611][Heoi2014]大工程 Description 国家有一个大工程,要给一个非常大的交通网络里建一些新的通道.  我们这个国家位置非常特殊,可以看成是一个单位边权的树,城市位于顶 ...

  2. EasyPlayerPro RTMP播放器助力远程娃娃机直播抓娃娃技术方案

    远程娃娃机 目前市面上娃娃机的方案有很多种.核心的技术流程就是实现远程直播加上对娃娃机手臂的远程操作.其中最主要的技术还是视频直播方案,需要低延时,视频秒开等流媒体技术. 最简单的直播方案 视频直播方 ...

  3. svn服务器 vim 修改 authz passwd 添加用户

    进入svn服务器 vim 修改 authz passwd 添加用户 SVN服务器之------2,配置PhpStorm连接SVN服务器(其他IDE大同小异) - 学到老死 - 博客园 https:// ...

  4. POJ 2442 Sequence【堆】

    题目链接:http://poj.org/problem?id=2442 题目大意:给出一个m*n的矩阵,从每一行中取出一个数相加.能得到n^m个不同的结果.要求输出当中前n项. 建立一个以n元数组为底 ...

  5. SVG圆盘时钟动画

    在线演示 本地下载

  6. Linux-3.14.12内存管理笔记【kmalloc与kfree实现】【转】

    本文转载自:http://blog.chinaunix.net/uid-26859697-id-5573776.html kmalloc()是基于slab/slob/slub分配分配算法上实现的,不少 ...

  7. iOS开发数据库-FMDB

    前言 FMDB是以OC的方式封装了SQLite的C语言API,使用起来更加面向对象,省去了很多麻烦.冗余的C语言代码:对比苹果自带的Core Data框架,更加轻量级和灵活:提供了多线程安全的数据库操 ...

  8. 标准兼容HTML5输入框提示信息的插件iHolder_v0.1.06.21.2014_预览版

    由于版面限制,简单说下,详细的内容及在线预览.预览版压缩包,见这里http://levi.cg.am/archives/3507 为什么说是标准兼容: 因为大多数placeholder插件是这样兼容的 ...

  9. Zabbix数据库清理历史数据

    Zabbix清理历史数据 Zabbix是个很好的监控软件,随着公司监控项目越来越多,数据越来越多,zabbix负载重,可能造成系统性能下降. Zabbix里面最大的表就是历史记录表,history,h ...

  10. Java常用类Date、Calendar、SimpleDateFormat详解

    Date类 java.util 包提供了 Date 类来封装当前的日期和时间,Date 类提供两个构造函数来实例化 Date 对象 第一个构造函数使用当前日期和时间来初始化对象   Date( ) 第 ...