071_salesforce 页面自动检索匹配显示设置
通常我们会有需求:在搜索框中输入关键词,点击后面搜索,相关数据会显示在输入框的下面供选择,如下图

First I am assuming that you already have Static Resource of named “AutoCompleteWithModal“. This Static resource has all images, CSS and JQuery library needed to implement this component.
使用JQueryUI 自动完成组件
Visualforce Account_JSON :
<apex:page Controller="AccountJSONCreator" contentType="application/x-JavaScript; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">
{!JSON}
</apex:page>
Controller AccountJSONCreator :
public with sharing class AccountJSONCreator {
public String getJSON()
{
String AccountName = Apexpages.currentPage().getParameters().get('AccName');
List<AccountWrapper> wrp = new List<AccountWrapper>();
for (Account a : [Select a.Id, a.Website, a.Name, a.BillingCountry, a.BillingCity
From
Account a
WHERE Name Like : '%'+AccountName+'%' ]) {
AccountWrapper w = new AccountWrapper (a.Name, nullToBlank (a.BillingCountry), nullToBlank (a.BillingCity));
wrp.add(w);
}
return JSON.serialize(wrp);
}
public String nullToBlank(String val)
{
return val == null ?'':val;
}
public class AccountWrapper
{
String AccName,BillingCountry,BillingCity;
public AccountWrapper(String aName, String bCountry, String bCity)
{
AccName = aName;
BillingCountry = bCountry;
BillingCity = bCity;
}
}
static testMethod void AccountJSONCreatorTest() {
AccountJSONCreator obj = new AccountJSONCreator();
obj.getJSON();
}
}
Now let’s create a Component which will make AJAX request to above visualforce page “Account_JSON” and Parse JSON page using JQuery.
Component Autocomplete_Component :
<apex:component>
<apex:attribute name="ComponentLabel" description="Label of Component"
type="String" required="true"/> <apex:stylesheet value="{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryUI/css/ui-lightness/jquery-ui-1.8.17.custom.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryUI/js/jquery-1.7.1.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryUI/js/jquery-ui-1.8.17.custom.min.js')}"/>
<apex:stylesheet value="{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryModal/css/basic.css')}"/> <style type="text/css">
.ui-autocomplete-loading { background: white url('{!URLFOR($Resource.AutoCompleteWithModal, 'AjaxLoad.gif')}') right center no-repeat; }
</style> {!ComponentLabel} <apex:inputText id="theTextInput"/> <script type="text/javascript">
//$ac - AutoComplete $ac = jQuery.noConflict(); function getLoadingImage()
{
var loadImagURL = "{!URLFOR($Resource.AutoCompleteWithModal, 'BigLoad.gif')}";
var retStr = ['<img src="', loadImagURL ,'" title="loading..." alt="loading..." class="middleAlign" />'];
return retStr.join("");
} var sourcePage = 'https://c.ap1.visual.force.com/apex/Account_JSON?core.apexpages.devmode.url=0'; $ac(function() {
var txtVal = $ac('[id="{!$Component.theTextInput}"]');
//This method returns the last character of String
function extractLast(term) {
return term.substr(term.length - 1);
} $ac('[id="{!$Component.theTextInput}"]').autocomplete({
source: function( request, response ) { //Abort Ajax
var $this = $ac(this);
var $element = $ac(this.element);
var jqXHR = $element.data('jqXHR');
if(jqXHR)
jqXHR.abort(); $ac('[id="{!$Component.theTextInput}"]').addClass('ui-autocomplete-loading');
//prompt('',sourcePage+'&key='+txtVal.val());
$element.data('jqXHR',$ac.ajax({
url: sourcePage+'&AccName='+txtVal.val(),
dataType: "json",
data: {
},
success: function( data ) {
response( $ac.map( data , function( item ) {
return {
label: '<a>'+
item.AccName+"<br />"+
'<span style="font-size:0.8em;font-style:italic">'
+item.BillingCity+', '+item.BillingCountry+
"</span></a>",
value: item.AccName
}
}));
},
complete: function() { //This method is called either request completed or not
$this.removeData('jqXHR'); //remove the class responsible for loading image
$ac('[id="{!$Component.theTextInput}"]').removeClass('ui-autocomplete-loading');
}
})
); },
search: function() {
/*
// If last character is space
var term = extractLast(this.value);
if(term == " ")
{
return true;
}
*/ //If String contains at least 1 space
if (this.value.indexOf(" ") >= 0)
{
$ac('[id="{!$Component.theTextInput}"]').autocomplete('option', 'delay', 500);
return true;
}
return false;
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function(event, ui) {
var selectedObj = ui.item;
//alert(selectedObj.compId);
//getCompanyDetail(selectedObj.compId);
return true;
}
}).data("autocomplete")._renderItem = autoCompleteRender; }); function autoCompleteRender(ul, item) {
return $ac("<li></li>").data("item.autocomplete", item).append(item.label).appendTo(ul);
} </script>
</apex:component>
Viusalforce Page : AutoCompleteDemo
<apex:page >
<apex:form >
<c:autocomplete_component ComponentLabel="Enter Account Name : "/>
</apex:form>
</apex:page>
071_salesforce 页面自动检索匹配显示设置的更多相关文章
- 2017春 前端自动化(二) 页面自动刷新、sass与css转换的使用、pxToRem直观转换
2017春 前端自动化(二) 页面自动刷新.sass与css转换的使用.pxToRem直观转换 引言: 此文要演示:浏览器页面自动刷新:移动端px与rem的转换,简单直观化:使用sass自动生 ...
- Go 实现 自动检索 API 错误码代码行 并 打印成文档,例 markDown 形式等
作者:林冠宏 / 指尖下的幽灵 掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8 博客:http://www.cnblogs.com/linguan ...
- EasyUI 1.3.2 中 Combobox自动检索 键盘上下选择Bug问题
EasyUI 自带的Combobox控件,提供了下拉列值自动检索功能. 在用到的EasyUI 1.3.2版本中还是有点问题,在键盘上下键移动选择过程中只能定位在第一个,不能正常向下移动 问题解决方式: ...
- 【前台页面 BUG】回车按钮后,页面自动跳转
点击回车按钮后,页面自动的迅速跳转 原因: 表单隐式提交了. 解决方法: 在方法执行完成后,加上return false; 代码如下: /** * 注册按钮的点击事件 */ $("#regi ...
- PHP 页面自动刷新可借助JS来实现,简单示例如下:
<?php echo "系统当前时间戳为:"; echo ""; echo time(); //<!--JS 页面自动刷新 --> echo ...
- 详解Grunt插件之LiveReload实现页面自动刷新(两种方案)
http://www.jb51.net/article/70415.htm 含Grunt系列教程 这篇文章主要通过两种方案详解Grunt插件之LiveReload实现页面自动刷新,需要的朋友可以 ...
- 方法总结:如何实现html页面自动刷新
使用场景: 1. 页面需要定时刷新,实时加载数据,需要实时查看监控数据(H5中的WebSocket和SSE可以实现局部刷新) 2. 一定时间之后跳转到指定页面(登录注册之类) 3. 前端开发使用伪数据 ...
- springboot 学习之路 7(静态页面自动生效问题)
目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...
- HTML 页面自动刷新
学习就是一个不断积累的过程,每一天能够学到一点新东西说明自己就在进步!! HTML head 里面设置页面自动刷新功能 <meta http-equiv="Refresh" ...
- 实现html页面自动刷新的几种方式
自动页面刷新通常会用在对数据的实时性比较敏感的网站中,比如股票走势等,另外在普通的页面自动跳转中也会使用到页面自动刷新技术. 页面刷新我见过的有三种方式,下面来一一说明 1.通过在<head&g ...
随机推荐
- ChatGPT 背后的“功臣”——RLHF 技术详解
OpenAI 推出的 ChatGPT 对话模型掀起了新的 AI 热潮,它面对多种多样的问题对答如流,似乎已经打破了机器和人的边界.这一工作的背后是大型语言模型 (Large Language Mode ...
- 小项目中vuex使用频率不太多我们完全可以用provide inject 来代替可以让项目小不少
在一般小型项目中vuex实在是太浪费了所以我们可以用到 vue中的provide inject 代替 1.在vue3中我们先另起一个 文件创建一个全局的状态和方法的地方(如果你的全局状态特别的多记得要 ...
- 结构型模式 - 代理模式Proxy
学习而来,代码是自己敲的.也有些自己的理解在里边,有问题希望大家指出. 代理模式的定义与特点 代理模式的定义:由于某些原因需要给某对象提供一个代理以控制对该对象的访问.这时,访问对象不 ...
- SpringBoot 2.x 在Tomcat8上无法运行,报无法访问错误
非法访问:此Web应用程序实例已停止.无法加载[].为了调试以及终止导致非法访问的 这仅是我的一个Filter重写的时候没有重写他的其他两个方法,导致我在Tomcat8上不能运行,但在Tomcat9上 ...
- rpmbuild时为什么会出现空的debugsourcefiles.list?
错误: 空 %file 文件 /home/user/rpmbuild/BUILD/xxxx-0.1/debugsourcefiles.list 你看错误的里边有一个%file,这是使用spec文件构建 ...
- Ubuntu/linux下最强大的下载工具-aria2
aria2 是 Linux 下一个不错的高速下载工具 .由于它具有分段下载引擎,所以支持从多个地址或者从一个地址的多个连接来下载同一个文件.这样自然就大大加快了文件的下载速 度.aria2 也具有断点 ...
- 大规模 IoT 边缘容器集群管理的几种架构-3-Portainer
前文回顾 大规模 IoT 边缘容器集群管理的几种架构-0-边缘容器及架构简介 大规模 IoT 边缘容器集群管理的几种架构-1-Rancher+K3s 大规模 IoT 边缘容器集群管理的几种架构-2-H ...
- Blue Mary开公司
Blue Mary开公司 题面:[JSOI2008]Blue Mary开公司 题目大意: 每次加入一条形如 \(y=Px + S - P\) 的直线,询问 \(x=T\) 时此处最高的 \(y\) 值 ...
- 钓鱼攻击之:OFFICE 宏后门文件钓鱼
钓鱼攻击之:OFFICE 宏后门文件钓鱼 目录 钓鱼攻击之:OFFICE 宏后门文件钓鱼 1 宏病毒介绍 1.1 Word 宏 1.2 Excel 4.0宏 2 生成 Word 宏后门 3 利用DOC ...
- 代码随想录算法训练营day10 | leetcode 232.用栈实现队列 225. 用队列实现栈
基础知识 使用ArrayDeque 实现栈和队列 stack push pop peek isEmpty() size() queue offer poll peek isEmpty() size() ...