Uncaught TypeError:无法读取未定义的属性“长度” - 无法修复/调试 [英] Uncaught TypeError: Cannot read property 'length' of undefined - Cannot fix/debug this

查看:165
本文介绍了Uncaught TypeError:无法读取未定义的属性“长度” - 无法修复/调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://darrenbachan.com/

http://darrenbachan.com/js/main.js

我不知道如何解决这个问题。我根本不知道JavaScript来调试或理解其他文章/线程。为了显示错误,点击一个不是前两个的项目,你会在控制台中看到它。

I have no idea how to fix this. I don't know javascript at all to debug or understand other articles/threads. To get the error to appear, click onto a project that's not one of the first two and you'll see it in the console.

我有项目:

'zeckoshop' : {
            'title' : 'zeckoShop',
            'description' : 'An all-in-one ecommerce platform designed to seamlessly integrate with your business operations.',
            'link' : 'http://darrenbachan.com/playground/zeckoshop/index.html',
            'images': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ],
            'tags': [
                'Web Design',
                'Web Development'
            ],
            'process-description' : 'An all-in-one ecommerce platform designed to seamlessly integrate with your business operations.',
            'process-wireframes': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ]
        },

        'diamond-hand-car-wash' : {
            'title' : 'Diamond Hand Car Wash',
            'description' : 'Feeling luxurious is only one car wash away.',
            'link' : 'http://darrenbachan.com/playground/diamond-hand-car-wash/index.html',
            'images': [
                '/images/diamond-hand-car-wash/diamond-1.jpg'
            ],
            'tags': [
                'Web Design',
                'Web Development'
            ],
            'process-description' : 'test',
            'process-wireframes': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ]
        },

        'edutravel-for-credit' : {
            'title' : 'EduTravel For Credit',
            'description' : 'Innovative travel for credit. Completely engage in your learning through exploration and discovery.',
            'link' : '',
            'images': [
                '/images/edutravel-for-credit/edu-1.jpg',
                '/images/edutravel-for-credit/edu-2.jpg',
                '/images/edutravel-for-credit/edu-3.jpg',
                '/images/edutravel-for-credit/edu-4.jpg'
            ],
            'tags': [
                'Web Design',
                'Newsletter'
            ]
        },

因为'process-description'和'process-wireframes'aren'在项目'edutravel-for-credit'上它会产生这个错误。

Because 'process-description' and 'process-wireframes' aren't on project 'edutravel-for-credit' it creates this error.

这个内容的代码是:

The code that pulls this content is:

if($('#process-description').length) {
            $('#process-description').html(projectData['process-description']).show();
        } else {
            $('#process-work').hide();
        }
        $('#process-wireframes').empty('');

        $.each(projectData['process-wireframes'], function(item) {
            $('#process-wireframes').append('<div class="project-gallery"><img src='+projectData['process-wireframes'][item]+' /></div>')
        });

它将内容放入此html:

It spits content into this html:

<div id="process-work">
    <h2 id="process-title">Process Work</h2>
    <p id="process-description"></p>
    <div id="process-wireframes"></div>
</div>

我从字面上不知道如何调试此问题,并且可以使用我可以获得的任何帮助。无论是在这里还是在Skype会话或其他东西。我需要绝对地显示这些内容。

I literally do not know how to debug this issue and can use any help I can get. Whether it be on here or a skype session or something. I need to display this content desperately.

推荐答案

在试图迭代它之前测试属性是否存在。 b
$ b

Test whether the property exists before trying to iterate over it.

if (projectData['process-wireframes']) {
    $.each(projectData['process-wireframes'], function(item) {
        $('#process-wireframes').append('<div class="project-gallery"><img src='+projectData['process-wireframes'][item]+' /></div>')
    });
}

错误发生是因为 $的代码。每个开始于:

The error is happening because the code for $.each starts with:

each: function( obj, callback, args ) {
    var value,
        i = 0,
        length = obj.length,
        isArray = isArraylike( obj );

未定义 obj 时, code> length = obj.length 出错。

When obj is undefined, the line length = obj.length gets an error.

这篇关于Uncaught TypeError:无法读取未定义的属性“长度” - 无法修复/调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆