开发者

jQuery autocompletion event

开发者 https://www.devze.com 2023-03-16 23:26 出处:网络
I try to develop my first MVC3 application, but there are problems including a jQuery autocompletion select event. When selecting an item, nothing happens. No error, no message. I\'ve used the search

I try to develop my first MVC3 application, but there are problems including a jQuery autocompletion select event. When selecting an item, nothing happens. No error, no message. I've used the search function to solve the problem, but there was no working solution for me.

Here's my Razor View Code including the javascript.

<script language="javascript" type="text/javascript">

$(document).ready(function () {
    $("#search").autocomplete('@Url.Action("Search")', {
        width: 200,
        matchContains: true,
        dataType: 'json',
        select: function(event, ui) {
            console.log('event');
        },
        delay: 10,
        minChars: 3,
        matchSubset: 1,
        maxItemsToShow: 10,
        parse: function (data) 
               {
                   var rows = new Array();
                   for (var i = 0; i < data.length; i++) 
                   {
                       rows[i] = { data: data[i].Value, value: data[i].Guid, result: data[i].Value 
                   };
               }
               return rows;
        },
        formatItem: function (row, i, n) 
                    {
 开发者_开发问答                       return row;
                    },
        highlight: function (value, pattern) 
                   {
                       value = value.replace(pattern, '<strong style="background-color:yellow;">' + pattern + '</strong>');
                       return value;
                   },
        select: function (value, data)
               { 
                   alert('You selected: ' + value + ', ' + data); 
               },
        extraParams: {
            active: function () 
                    {
                        var message = new Array();
                        for (i = 0; i < document.forms["filter"].filters.length; i++)
                            if (document.forms["filter"].filters[i].checked) 
                            {
                                message[i] = document.forms["filter"].filters[i].value;
                            }
                        return message;
                    }
                }

        });
        });

Following libraries are used:

* Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $

* jQuery JavaScript Library v1.5.1

May someone help me, please?


Take a look at the Autocomplete widget in jQuery.UI:

http://jqueryui.com/demos/autocomplete/

There's also an interesting article on how to use it with ASP.NET (not MVC, but close enough):

http://www.dotnetcurry.com/ShowArticle.aspx?ID=515

0

精彩评论

暂无评论...
验证码 换一张
取 消