Javascript 未捕获的TypeError:undefined不是getAttribute方法上的函数
我有一个函数,需要获取数组(county)中元素的“id” 我找到了名字(countyName),但不知怎么的Javascript 未捕获的TypeError:undefined不是getAttribute方法上的函数,javascript,html,arrays,ember.js,Javascript,Html,Arrays,Ember.js,我有一个函数,需要获取数组(county)中元素的“id” 我找到了名字(countyName),但不知怎么的 foundCounty.getAttribute('id'); 返回错误:未捕获类型错误:未定义不是函数 代码的其余部分: function findCountyMatchFromServer(){ var county = getElementAsString("ddlCounty"); return county; }; var county = [{ i
foundCounty.getAttribute('id');
返回错误:未捕获类型错误:未定义不是函数
代码的其余部分:
function findCountyMatchFromServer(){
var county = getElementAsString("ddlCounty");
return county;
};
var county = [{
id: '1',
title: "Harjumaa",
avgPrice: '1234',
avgSurface: '23',
}, {
id: '2',
title: 'Hiiumaa',
avgPrice: '5345',
avgSurface: '243',
}]
谢谢大家! 如果这是一个Ember数组对象,请使用foundCountry.get('id'),而不是.getAttribute。getAttribute不是一个函数。查看文档:这不是一个余烬对象,您必须使用
Em.get(foundCountry,'id')
还有一个简单的foundCountry.id
…是的,确实存在,但这确实假设foundCountry存在,如果它不存在,您有一个很好的ol'fashion空引用问题。通过替换var countyId=foundCounty.getAttribute('id')解决了这个问题;var countyId=foundCounty.id;
function findCountyMatchFromServer(){
var county = getElementAsString("ddlCounty");
return county;
};
var county = [{
id: '1',
title: "Harjumaa",
avgPrice: '1234',
avgSurface: '23',
}, {
id: '2',
title: 'Hiiumaa',
avgPrice: '5345',
avgSurface: '243',
}]