简体   繁体   English

捕获TypeError:尽管有条件,但无法读取未定义的属性“ get”

[英]Getting Uncaught TypeError: Cannot read property 'get' of undefined in spite of the conditionals

I'm trying to retrieve images on Facebook Parse SDK, and I can't because of this error. 我正在尝试在Facebook Parse SDK上检索图像,但由于此错误,我无法。 And I don't know what i'm doing wrong because I use a conditional in order to no not to create a new variable if this is empty or undefined. 而且我不知道我在做什么错,因为我使用了条件语句,以便在不为空或未定义的情况下不创建新变量。 This is the code (the console log points the error in the line where i'm creating the var ImageFl): 这是代码(控制台日志在我创建var ImageFl的行中指出了错误):

var Encharcamientos1 = Parse.Object.extend("Report");
var query = new Parse.Query(Inundaciones1);
query.equalTo("Tipo_Reporte", "Encharcamientos");
query.find({


success: function(results) {
    // Do something with the returned Parse.Object values

for (var i = 0; i < results.length; i++) {
if (!object.get('ImageFile') || object.get('ImageFile') !== '' || typeof object.get('ImageFile') !== 'undefined') {
var imageFl = object.get('ImageFile');
var imageURL = imageFl.url();
$('.imagen')[0].src = imageURL;
}

    var object = results[i];
     L.marker([object.get('Latitud'),object.get('Longitud') ], {icon: EncharcamientosIcon}).bindPopup(' <p><span class="grande"> ' + object.get('Tipo_Reporte') + ' </span></p><p>Fecha: ' + object.get('Fecha') + ' </p><p>Hora: ' + object.get('Hora') + '<div class="imagen"></div>' + '</p><p>Comentarios:<br /> ' + noundefined(object.get('Comentario')) + '</p>').addTo(Encharcamientos).addTo(todos);
    }
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});

The object wasn't being set before the if statement. 没有在if语句之前设置对象。 update, added code from comments 更新,添加了注释中的代码

var Encharcamientos1 = Parse.Object.extend("Report");
var query = new Parse.Query(Inundaciones1);
query.equalTo("Tipo_Reporte", "Encharcamientos");

query.find({

    success: function(results) {
        // Do something with the returned Parse.Object values

        for (var i = 0; i < results.length; i++) {
            var object = results[i]; // <-- THIS NEEDS TO BE BEFORE IF STATEMENT

            var imageFl = object.get('ImageFile');
            alert(imageFl);

            if (imageFl !== '' && typeof imageFl !== 'undefined') {
                var imageURL = imageFl.url();
                $('.imagen')[0].src = imageURL;
            }

            L.marker([object.get('Latitud'),object.get('Longitud') ], {icon: EncharcamientosIcon}).bindPopup(' <p><span class="grande"> ' + object.get('Tipo_Reporte') + ' </span></p><p>Fecha: ' + object.get('Fecha') + ' </p><p>Hora: ' + object.get('Hora') + '<div class="imagen"></div>' + '</p><p>Comentarios:<br /> ' + noundefined(object.get('Comentario')) + '</p>').addTo(Encharcamientos).addTo(todos);
        }
    },

    error: function(error) {
        alert("Error: " + error.code + " " + error.message);
    }

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取未定义的属性“get” - Uncaught TypeError: Cannot read property 'get' of undefined Tumblr API获取“未捕获的TypeError:无法读取未定义的属性”类型” - Tumblr API getting 'Uncaught TypeError: Cannot read property 'type' of undefined' 在JavaScript上获取“未捕获的TypeError:无法读取未定义的属性&#39;top&#39;” - Getting “Uncaught TypeError: Cannot read property 'top' of undefined” on javascript 我收到“未捕获的类型错误:无法读取未定义的属性‘注释’”错误 - Im getting a "Uncaught TypeError: Cannot read property 'note' of undefined" error 获取'未捕获的类型错误:无法读取未定义的属性'帮助者'' - Getting 'Uncaught TypeError: Cannot read property 'helpers' of undefined' 获取调试错误:未捕获的类型错误:无法读取未定义的属性“值” - Getting degugging error: Uncaught TypeError: Cannot read property 'value' of undefined 获取错误:“未捕获的类型错误:无法读取未定义的属性‘长度’” - Getting error: "Uncaught TypeError: Cannot read property 'length' of undefined" 捕获TypeError:无法读取未定义的属性“ push” - Getting Uncaught TypeError: Cannot read property 'push' of undefined Js 获取 Uncaught TypeError:无法读取未定义的属性但仍在工作 - Js getting Uncaught TypeError: Cannot read property of undefined but still working 获取&#39;未捕获的TypeError:无法读取属性&#39;地理编码&#39;未定义&#39;错误 - Getting 'Uncaught TypeError: Cannot read property 'geocode' of undefined ' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM