XML元素到本地javascript变量

时间:2014-04-24 22:28:47

标签: javascript xml

我正在编程学生,我正在寻找项目方面的帮助。

我无法将XML元素设置为可在我的代码中使用的本地javascript变量。我认为它与这段代码有关,但我不确定如何纠正代码。我正在使用本地网络主机。任何建议将不胜感激!

上下文的项目文件夹:https://www.dropbox.com/sh/hdqxbb1bv7lpsqe/0pj93yQR8Z

var xmlToCatshipObjectList = function() {

    var r = $.Deferred();

    $.get(xmlDoc, function(doc){
        console.log("xmlToCatshipObjectList");
        $(xmlDoc).find("catship").each(function(){

            var $this = $(this);
            var health = $this.find('health-hits');
            var speed = $this.find('speed');
            var catNumber = $this.find('cats');
            var shipX = $this.find('xpos');
            var shipY = $this.find(k'ypos');


            shipList.push(
                new catship(health, speed, catNumber, shipX, shipY)
            );
        });
    });

    setTimeout(function () {
        r.resolve();
    }, 2500);

    return r;
};


function catship(health, speed, catNumber, shipX, shipY){
    this.health = health;
    this.speed = speed;
    this.catNumber = catNumber;
    this.shipX = shipX;
    this.shipY = shipY;
}

0 个答案:

没有答案