admin管理员组

文章数量:1023045

I am getting this and a couple other weird error messages on my main ASP MVC 3 layout page.

I am using the following scripts

<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/typeahead.js")" type="text/javascript"></script>

And trying to get the typeahead.js to work in our nav bar. Below is the code I currently have on my machine. I had this working at one point in time, however after a sync up with a coworker the typeahead search does not work anymore and I haven't been able to track down the issue.

The first line in the code below gives the following error

Uncaught TypeError: Cannot read property 'Constructor' of undefined

If I ment out the protoype.blur function, however, I then get this error

Uncaught TypeError: Object [object Object] has no method 'typeahead' 

Which points to the $('.AgentSearch .typeahead).typeahead function. Been stuck on this for hours, any help would be greatly appreciated. Thanks

        // Workaround for bug in mouse item selection
        $.fn.typeahead.Constructor.prototype.blur = function () {
            var that = this;
            setTimeout(function () { that.hide() }, 250);
        };

        $('.AgentSearch').typeahead({
            source: function (term, process) {
                var url = '@Url.Action("GetAgents", "Agent")';
                var agents = [];
                map = {};
                return ($.getJSON(url, { term: term }, function (data) {
                    $.each(data, function (i, item) {
                        map[item.Name] = item;
                        agents.push(item.Name);
                    });
                    process(agents);
                }));
            },
            highlighter: function (item) {
                var p = map[item];
                var display = ''
                             + "<div class='typeahead_wrapper'>"
                             + "<div class='typeahead_labels'>"
                             + "<div class='typeahead_primary'>" + p.Name + "</div>"
                             + "<div class='typeahead_third'><i>LastFour:</i> " + p.LastFour + "</div>"
                             + "</div>"
                             + "</div>";
                return display;
            },
            updater: function (item) {
                window.location.href = ("/Monet/Agent/Details/" + map[item].SymetraNumber);
            }
        });

Here is the search box I'm binding this to

            <form class="navbar-search pull-left">   
                <input type="text" name="names" value="" id="AgentSearch" class="search-query" data-provide="typeahead" placeholder=" Agent Search"/> 
            </form>

EDIT

Here are the script tags as they're rendered by the browser

<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="/Scripts/typeahead.js" type="text/javascript"></script>

I am getting this and a couple other weird error messages on my main ASP MVC 3 layout page.

I am using the following scripts

<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/typeahead.js")" type="text/javascript"></script>

And trying to get the typeahead.js to work in our nav bar. Below is the code I currently have on my machine. I had this working at one point in time, however after a sync up with a coworker the typeahead search does not work anymore and I haven't been able to track down the issue.

The first line in the code below gives the following error

Uncaught TypeError: Cannot read property 'Constructor' of undefined

If I ment out the protoype.blur function, however, I then get this error

Uncaught TypeError: Object [object Object] has no method 'typeahead' 

Which points to the $('.AgentSearch .typeahead).typeahead function. Been stuck on this for hours, any help would be greatly appreciated. Thanks

        // Workaround for bug in mouse item selection
        $.fn.typeahead.Constructor.prototype.blur = function () {
            var that = this;
            setTimeout(function () { that.hide() }, 250);
        };

        $('.AgentSearch').typeahead({
            source: function (term, process) {
                var url = '@Url.Action("GetAgents", "Agent")';
                var agents = [];
                map = {};
                return ($.getJSON(url, { term: term }, function (data) {
                    $.each(data, function (i, item) {
                        map[item.Name] = item;
                        agents.push(item.Name);
                    });
                    process(agents);
                }));
            },
            highlighter: function (item) {
                var p = map[item];
                var display = ''
                             + "<div class='typeahead_wrapper'>"
                             + "<div class='typeahead_labels'>"
                             + "<div class='typeahead_primary'>" + p.Name + "</div>"
                             + "<div class='typeahead_third'><i>LastFour:</i> " + p.LastFour + "</div>"
                             + "</div>"
                             + "</div>";
                return display;
            },
            updater: function (item) {
                window.location.href = ("/Monet/Agent/Details/" + map[item].SymetraNumber);
            }
        });

Here is the search box I'm binding this to

            <form class="navbar-search pull-left">   
                <input type="text" name="names" value="" id="AgentSearch" class="search-query" data-provide="typeahead" placeholder=" Agent Search"/> 
            </form>

EDIT

Here are the script tags as they're rendered by the browser

<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="/Scripts/typeahead.js" type="text/javascript"></script>
Share Improve this question edited Sep 12, 2013 at 22:34 NealR asked Sep 12, 2013 at 22:24 NealRNealR 10.7k61 gold badges167 silver badges306 bronze badges 2
  • Looks like the typeahead.js file isn't included properly, did you check the outputted url in your markup. – adeneo Commented Sep 12, 2013 at 22:26
  • Yes, everything looks on the up and up. Just added to the post. – NealR Commented Sep 12, 2013 at 22:35
Add a ment  | 

1 Answer 1

Reset to default 0

It looks like typeahead is not defined.

If you're trying to extend typeahead, this article may help: Extend the bootstrap-typeahead in order to take an object instead of a string

$.fn will always return an object ('[]'), this is why the error change when you ment-out .prototype.blur, but they're both indicating 'typeahead' doesn't exist.

Just a guess, but it could be a synchronicity issue where your code is running before the library loads.

I am getting this and a couple other weird error messages on my main ASP MVC 3 layout page.

I am using the following scripts

<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/typeahead.js")" type="text/javascript"></script>

And trying to get the typeahead.js to work in our nav bar. Below is the code I currently have on my machine. I had this working at one point in time, however after a sync up with a coworker the typeahead search does not work anymore and I haven't been able to track down the issue.

The first line in the code below gives the following error

Uncaught TypeError: Cannot read property 'Constructor' of undefined

If I ment out the protoype.blur function, however, I then get this error

Uncaught TypeError: Object [object Object] has no method 'typeahead' 

Which points to the $('.AgentSearch .typeahead).typeahead function. Been stuck on this for hours, any help would be greatly appreciated. Thanks

        // Workaround for bug in mouse item selection
        $.fn.typeahead.Constructor.prototype.blur = function () {
            var that = this;
            setTimeout(function () { that.hide() }, 250);
        };

        $('.AgentSearch').typeahead({
            source: function (term, process) {
                var url = '@Url.Action("GetAgents", "Agent")';
                var agents = [];
                map = {};
                return ($.getJSON(url, { term: term }, function (data) {
                    $.each(data, function (i, item) {
                        map[item.Name] = item;
                        agents.push(item.Name);
                    });
                    process(agents);
                }));
            },
            highlighter: function (item) {
                var p = map[item];
                var display = ''
                             + "<div class='typeahead_wrapper'>"
                             + "<div class='typeahead_labels'>"
                             + "<div class='typeahead_primary'>" + p.Name + "</div>"
                             + "<div class='typeahead_third'><i>LastFour:</i> " + p.LastFour + "</div>"
                             + "</div>"
                             + "</div>";
                return display;
            },
            updater: function (item) {
                window.location.href = ("/Monet/Agent/Details/" + map[item].SymetraNumber);
            }
        });

Here is the search box I'm binding this to

            <form class="navbar-search pull-left">   
                <input type="text" name="names" value="" id="AgentSearch" class="search-query" data-provide="typeahead" placeholder=" Agent Search"/> 
            </form>

EDIT

Here are the script tags as they're rendered by the browser

<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="/Scripts/typeahead.js" type="text/javascript"></script>

I am getting this and a couple other weird error messages on my main ASP MVC 3 layout page.

I am using the following scripts

<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/typeahead.js")" type="text/javascript"></script>

And trying to get the typeahead.js to work in our nav bar. Below is the code I currently have on my machine. I had this working at one point in time, however after a sync up with a coworker the typeahead search does not work anymore and I haven't been able to track down the issue.

The first line in the code below gives the following error

Uncaught TypeError: Cannot read property 'Constructor' of undefined

If I ment out the protoype.blur function, however, I then get this error

Uncaught TypeError: Object [object Object] has no method 'typeahead' 

Which points to the $('.AgentSearch .typeahead).typeahead function. Been stuck on this for hours, any help would be greatly appreciated. Thanks

        // Workaround for bug in mouse item selection
        $.fn.typeahead.Constructor.prototype.blur = function () {
            var that = this;
            setTimeout(function () { that.hide() }, 250);
        };

        $('.AgentSearch').typeahead({
            source: function (term, process) {
                var url = '@Url.Action("GetAgents", "Agent")';
                var agents = [];
                map = {};
                return ($.getJSON(url, { term: term }, function (data) {
                    $.each(data, function (i, item) {
                        map[item.Name] = item;
                        agents.push(item.Name);
                    });
                    process(agents);
                }));
            },
            highlighter: function (item) {
                var p = map[item];
                var display = ''
                             + "<div class='typeahead_wrapper'>"
                             + "<div class='typeahead_labels'>"
                             + "<div class='typeahead_primary'>" + p.Name + "</div>"
                             + "<div class='typeahead_third'><i>LastFour:</i> " + p.LastFour + "</div>"
                             + "</div>"
                             + "</div>";
                return display;
            },
            updater: function (item) {
                window.location.href = ("/Monet/Agent/Details/" + map[item].SymetraNumber);
            }
        });

Here is the search box I'm binding this to

            <form class="navbar-search pull-left">   
                <input type="text" name="names" value="" id="AgentSearch" class="search-query" data-provide="typeahead" placeholder=" Agent Search"/> 
            </form>

EDIT

Here are the script tags as they're rendered by the browser

<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="/Scripts/typeahead.js" type="text/javascript"></script>
Share Improve this question edited Sep 12, 2013 at 22:34 NealR asked Sep 12, 2013 at 22:24 NealRNealR 10.7k61 gold badges167 silver badges306 bronze badges 2
  • Looks like the typeahead.js file isn't included properly, did you check the outputted url in your markup. – adeneo Commented Sep 12, 2013 at 22:26
  • Yes, everything looks on the up and up. Just added to the post. – NealR Commented Sep 12, 2013 at 22:35
Add a ment  | 

1 Answer 1

Reset to default 0

It looks like typeahead is not defined.

If you're trying to extend typeahead, this article may help: Extend the bootstrap-typeahead in order to take an object instead of a string

$.fn will always return an object ('[]'), this is why the error change when you ment-out .prototype.blur, but they're both indicating 'typeahead' doesn't exist.

Just a guess, but it could be a synchronicity issue where your code is running before the library loads.

本文标签: