无法读取 Backbone.js 中未定义的属性'length'

dl5txlt9  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(126)

检查长度时出现未定义错误。请查看图片

this. updateConfiguration = _.debounce(this.updateConfiguration, 300); 
 this.set({ url: (HyprLiveContext.locals.siteContext.siteSubdirectory 11 ") + (slug ? "/" + slug : "") + "/p/" + this.get("productCode)} 
 this.lastConfiguration = []; 
 this.calculateHasPriceRange(conf); conf = undefined 
 this.on('sync', this.calculateHasPriceRange); 
 var variations = this.get('variations'); variations = undefined 
 var sum = 0; sum = 0 

 !.. 0) 
  { 
  var stockArray = []; 

  for(var 1=0; i<variations.length; i++) 
  {

原因何在?

hgqdbh6s

hgqdbh6s1#

尝试初始化数组,并检查是否为真实值:

var variations = [];

if (this.get('variations')) {
    variations = this.get('variations');
}

相关问题