AJAX AutoComplete的用法

调用页:
//在页面顶部注册控件
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
//TextBox控件
<asp:TextBox ID="txtTo" runat="server" Width="500px" AutoPostBack="True"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtenderSearch" 
	MinimumPrefixLength="1"//这是设置输入几个字符才开始调用搜索
	CompletionInterval="10" 
	runat="server"
	EnableCaching="true"
	ServicePath="AutoCompleteSend.asmx"//这是Web Services的路径
	ServiceMethod="GetToAddress"//这是处理搜索的Web Services下的一个方法
	TargetControlID="txtTo">//这是对应的TextBox
</cc1:AutoCompleteExtender>
被调用的Web Services:
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Script.Services;

using System.Web.Services.Protocols;

using System.Xml.Linq;



namespace MySystem.Email

{

    /// <summary>

    /// AutoCompleteSend 的摘要说明

    /// </summary>

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    [ToolboxItem(false)]

    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。

    [System.Web.Script.Services.ScriptService]//这个很重要,一定要有

    public class AutoCompleteSend : System.Web.Services.WebService

    {



        [WebMethod(EnableSession=true)]//这是打开支持Session的

        [ScriptMethod]//这个很重要,一定要有

        public string[] GetToAddress(string prefixText, int count)

        {

            //这里我就不详细写了,只要返回一个string[]就可以了

            return new string[]{"第一行","第二行"};

        }

    }

}

`el-autocomplete` 是 Element UI 提供的一个用于输入框自动补全功能的组件。它基于 Vue.js 开发,常用于搜索、建议等功能场景。以下是使用 `el-autocomplete` 的基本步骤: 1. 引入组件:首先需要在你的 Vue 项目中安装 Element UI,并引入 `el-autocomplete` 组件。例如,在 `main.js` 或其他入口文件里添加: ```js import { ElAutocomplete } from 'element-ui' Vue.component('el-autocomplete', ElAutocomplete) ``` 2. 注册并绑定到模板:然后在你的 Vue 实例模板中,创建一个 `<el-autocomplete>` 元素,并指定一些属性: ```html <template> <div> <el-autocomplete v-model="inputValue" placeholder="请输入关键词" :remote-method="search" <!-- 远程搜索方法 --> @select="handleSelect" <!-- 当用户选择一项时触发的事件 --> :trigger-on-focus="false" <!-- 控制是否在焦点获取时立即触发搜索 --> ></el-autocomplete> </div> </template> ``` 关键属性: - `v-model`: 表单的值,通常绑定用户的输入。 - `remote-method`: 自定义的远程搜索函数,一般会发送 AJAX 请求获取数据。 - `@select`: 选择事件处理器,可以处理选中的项。 3. 定义数据和方法:在你的 Vue 实例中,定义 `inputValue` 和相关的数据管理以及搜索方法: ```js export default { data() { return { inputValue: '', // 根据实际需求填充远程搜索的数据源 searchList: [], }; }, methods: { search(query) { // 使用输入值查询数据源 this.$axios.get('/api/search', { params: { keyword: query } }) .then(response => (this.searchList = response.data)) .catch(error => console.error(error)); }, handleSelect(item) { // 处理选中的 item console.log('Selected:', item); }, }, }; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值