admin管理员组文章数量:1395264
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('', '')
.prefix('qb', '')
.prefix('rdf', '')
.prefix('dcterms', '/')
.prefix('sdmx-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);
});
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./2009/01/eurostat/ns#')
.prefix('qb', 'http://purl/linked-data/cube#')
.prefix('rdf', 'http://www.w3/1999/02/22-rdf-syntax-ns#')
.prefix('dcterms', 'http://purl/dc/terms/')
.prefix('sdmx-measure', 'http://purl/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);
});
Share
Improve this question
edited Jun 16, 2011 at 9:05
Gaurav Saxena
1571 silver badge6 bronze badges
asked Jun 16, 2011 at 8:55
betabeta
5,70616 gold badges63 silver badges113 bronze badges
2 Answers
Reset to default 3values[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;
本文标签: javascriptwhy is array undefinedStack Overflow
版权声明:本文标题:javascript - why is array undefined? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744673251a2618954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论