开发者

why is array undefined?

when executing the following code firebug tells me: values[this.geo.value] is undefined what is the problem?

$.get('./RDFexamples/tin00089_test2.rdf', null, function (rdfXml) {
var rdf, json = {};
var values = new Array();

rdf = $.rdf()
    .load(rdfXml)
    .prefix('', 'http://ontologycentral.com/2009/01/eurostat/ns#')
    .prefix('qb', 'http://purl.org/linked-data/cube#')
    .prefix('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    .prefix('dcterms', 'http://开发者_如何学编程purl.org/dc/terms/')
    .prefix('sdmx-measure', 'http://purl.org/linked-data/sdmx/2009/measure#')
    .where('?observation a qb:Observation')
    .where('?observation dcterms:date ?date')
    .where('?observation sdmx-measure:obsValue ?measure')
    .where('?observation :geo ?geo')
    .each(function () {
        values[this.geo.value].push(this.measure.value);
        //alert(this.date.value)
        //alert(this.measure.value)
        //alert(this.geo.value)
    }
    );
    alert(values);
});


values[this.geo.value] is never initialized so you can't do .push because values[this.geo.value] is undefined, you first need to create an array in values[this.geo.value] before you can push things into it.

Pseudo-code example

if values[this.geo.value] == undefined {
    values[this.geo.value] = []
}
values[this.geo.value].push(...)


push is a method of the Array object itself - you are calling it on a value within the Array (which has probably not been set, hence 'undefined'). It's unclear what this.geo.value is, but assuming its the index of the array item you are trying to set, your options are:

values.push(this.measure.value);

or

values[this.geo.value] = this.measure.value;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜