Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获的TypeError:undefined不是getAttribute方法上的函数_Javascript_Html_Arrays_Ember.js - Fatal编程技术网

Javascript 未捕获的TypeError:undefined不是getAttribute方法上的函数

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

我有一个函数,需要获取数组(county)中元素的“id”

我找到了名字(countyName),但不知怎么的

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',
}]