Je reçois un " Impossible de lire la propriété 'tranche' undefined` message lorsque j'utilise le plugin jQuery scrollTo l'intérieur de cette fonction

Je suis en utilisant jQuery scrollTo plugin.

J'obtiens cette erreur dans mon JS Console:

16827Uncaught TypeError: Cannot read property 'slice' of undefined
d.fn.scrollToindex.html.js:16827
jQuery.extend.eachindex.html.js:662
d.fn.scrollToindex.html.js:16827
jQuery.extend.eachindex.html.js:662
jQuery.fn.jQuery.eachindex.html.js:276
d.fn.scrollToindex.html.js:16827
popupPlaceindex.html.js:18034
(anonymous function)index.html.js:17745
jQuery.extend._Deferred.deferred.resolveWithindex.html.js:1018
doneindex.html.js:7247
jQuery.ajaxTransport.send.script.onload.script.onreadystatechange

Quand je place $(".menu").scrollTo( $("li.matched").attr("id"), 800 ); à l'intérieur.

function popupPlace(dict) {
$popup = $('div#dish-popup');
$popup.render(dict,window.dishPopupTemplate);
if(typeof(dict.dish) === 'undefined') {
$popup.addClass('place-only');
} else {
$popup.removeClass('place-only');
}
var $place = $('div#dish-popup div.place');
var place_id = dict.place._id;
if(liked[place_id]) {
$place.addClass('liked');
} else {
$place.removeClass('liked');
}
if(dict.place.likes) {
$place.addClass('has-likes');
} else {
$place.addClass('zero-likes');
}
var tokens = window.currentSearchTermTokens;
var tokenRegex = tokens && new RegExp($.map(tokens, RegExp.escape).join('|'), 'gi');
$.each(dict.place.products, function(n, product) {
$product = $('#menu-item-'+product.id);
if(liked[place_id+'/'+product.id]) {
$product.addClass('liked');
}
if(tokens && matchesDish(product, tokens)) {
$product.addClass('matched');
$product.highlight(tokenRegex);
} else {
$product.removeClass('matched');
$product.removeHighlight();
}
if(product.likes) {
$product.addClass('has-likes');
} else {
$product.addClass('zero-likes');
}
});
$('#overlay').show();
$('#dish-popup-container').show();
//Scroll to matched dish
//$("a#scrolll").attr("href", "#" + $("li.matched").attr("id"));
//$("a#scrolll").attr("href", "#" + $("li.matched").attr("id"));
//$("a#scrolll").trigger("click");
$(".menu").scrollTo( $("li.matched").attr("id"), 800 );
//Hide dish results on mobile devices to prevent having a blank space at the bottom of the site
if (Modernizr.mq('only screen and (max-width: 640px)')) {
$('ol.results').hide();
}
$(".close-dish-popup").click(function() {
$("#overlay").hide();
$("#dish-popup-container").hide();
$('ol.results').show();
changeState({}, ['dish', 'place', 'serp']);
});
showPopupMap(dict.place, "dish-popup-map");
}

Toute suggestion pour résoudre ce problème?

Depuis que le code que vous avez fournies ci-dessus ne contient même pas slice il ne comprend pas la partie qui appelle l'exception. Ouvrir le JS qui est à l'origine de l'exception, de trouver cette ligne et de voir ce qui est exactement le undefined variable et ensuite travailler à partir de là à savoir pourquoi il n'est pas défini.

OriginalL'auteur alexchenco | 2011-11-11