我正在使用Appcelerator Titanium作爲Android應用程序,下面的代碼會在Android模擬器中生成一個錯誤,不確定它是否是我的Javascript或Appcelerator中的某個東西。使用getAttribute時出錯,爲什麼?
,它反對該項的getAttribute出於某種原因,並提供以下錯誤:
類型錯誤:無法調用未定義(APP://pages/xml.js#12)的方法 「的getAttribute」
(它可能不是#12以下由於格式化!! Thx)
任何人都可以闡明爲什麼getAttribute會導致問題?
下面是代碼:
// BEGIN SAMPLE CODE
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
var xmlDoc = this.responseXML.documentElement;
var xlocalestatus=xmlDoc.getElementsByTagName('Locations');
var xbooks=xmlDoc.getElementsByTagName('Books');
var newname = '';
for (i=0;i<xlocalestatus.length;i++)
{
newname = xbooks[i].getAttribute('Name');
Ti.API.info(newname);
}
};
// open the client
xhr.open('GET','http://myurl.com');
// send the data
xhr.send();
// END SAMPLE CODE
代碼也可在Pastie:這裏http://pastie.org/1670908
感謝