当执行以下代码时,firebug告诉我: valuesthis.geo.value是未定义的,问题是什么?
$.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);
});发布于 2011-06-16 09:05:10
valuesthis.geo.value从未初始化过,因此您无法执行.push,因为valuesthis.geo.value是未定义的,您首先需要在valuesthis.geo.value中创建一个数组,然后才能将内容推入其中。
伪码示例
if values[this.geo.value] == undefined {
values[this.geo.value] = []
}
values[this.geo.value].push(...)发布于 2011-06-16 09:02:15
push是数组对象本身的一个方法--您正在对数组中的值调用它(该值可能尚未设置,因此“未定义”)。还不清楚this.geo.value是什么,但假设它是要设置的数组项的索引,您的选项是:
values.push(this.measure.value);或
values[this.geo.value] = this.measure.value;https://stackoverflow.com/questions/6369319
复制相似问题