显示模板-URL修改 [英] Display Template - URL Modification

查看:71
本文介绍了显示模板-URL修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据托管属性的值更改URL或返回的结果.我们正在构建自定义职位申请,某些部门的模板有所不同.我正在尝试使用案例选择语句,但它返回的是JavaScript 运行时发生错误.我认为问题出在我的PostRender函数上.

I need to change the URL or a returned result based on the value of a managed property. We are building a custom job application and the template is different for certain departments. I am trying to use a case select statement but it's returning a javascript error when it runs. I'm thinking the problem is with my PostRender function.

  <div id="Item_Default">
<!--#_ 
        if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){
            var id = ctx.ClientControl.get_nextUniqueId();
            var itemId = id + Srch.U.Ids.item;
			var hoverId = id + Srch.U.Ids.hover;
			var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_JobPostings_HoverPanel.js";
            $setResultItem(itemId, ctx.CurrentItem);
			if(ctx.CurrentItem.IsContainer){
				ctx.CurrentItem.csr_Icon = Srch.U.getFolderIconUrl();
			}
			ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
            ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
_#-->
<!--#_
		var modifiedDate = new Date($getItemValue(ctx, "ClosingDateHR"));
		var closeDate = modifiedDate.toLocaleDateString();
			if (closeDate=="Invalid Date")
			{
				var closeDate = "Opened till filled";
			}
_#-->
<!--#_
		AddPostRenderCallback(ctx, fuction () {
		var custURL;
		var queryDepartment = new Department($getItemValue(ctx, "Department"));
		switch(queryDepartment) {
			case "Sheriff":
				custURL = "www.google.com";
			break;
			case "BCDCF":
				custURL = "www.microsoft.com";
			break;
			default:
				custURL = "www.foxnews.com";
		}
		custURL = queryDepartment;
		});			
_#-->

            <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="JobPostingItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
				<h4>
                    <a href="_#=custURL=#_">_#=ctx.CurrentItem.Title=#_</a>
                </h4>
                <div>
                    Department: _#=ctx.CurrentItem.Department=#_
                </div>
                
                <div>
                    <span>Closing: _#=closeDate=#_</span><span style="padding-left: 40px">Position Status: _#=ctx.CurrentItem.PositionStatusHR=#_</span>
                </div>

                <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
            </div>

    </div>



推荐答案

这里没有太多信息可以决定关于错误,您可以检查< o:p></o:p>

-第一步是检查浏览器控制台,它通常会具有错误并指向文件上的写行.

- Put a 'debugger' statement on your display template and refresh the page. This will help you debug the display template and figure out the issue.

要检查的内容

-缺少在显示模板中包含托管属性

-托管属性值为null,您正在对其进行一些操作  ;

	var modifiedDate = new Date(


getItemValue(ctx,"ClosingDateHR"));
getItemValue(ctx, "ClosingDateHR"));

例如如果'ClosingDateHR'为null,则Date将引发错误.

e.g. if 'ClosingDateHR' is null then Date will throw an error.


这篇关于显示模板-URL修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆