Хранить «Записи» из поля ввода в массив с конструктором объектов и JavaScript? - PullRequest
0 голосов
/ 19 октября 2018

У меня есть форма, которая запрашивает информацию о сотрудниках, их именах, возрасте, должности и деталях, и затем ее нужно добавить в div при нажатии кнопки «Добавить запись».

В настоящее время у меня есть настройка Object Constructor, но я немного растерялся из-за того, как передать детали в div и как мне написать функцию для этого, ранее я использовал Canvas для его отображения.

Вот мой HTML

    <!DOCTYPE html>
<html>
<head>
    <title>52DA session 5</title>
    <meta charset="utf-8" />
    <link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../css/employee_styles.css"/>
</head>
<body>
    <div id="container">
        <header>
            <h1 id="heading" class="blueTxt">Employee Records</h1>
        </header>
        <div class="left">
        <form>
            <fieldset>
                <legend><h2>Employee Details Entry</h2></legend>            
                <p class=><label>Name: <input class="text" type="text" id="name" /></label></p>
                <p><label>Age: <input class="text" type="text" id="age" /></label></p>
                <p><label>Position: <input class="text" type="text" id="position" /></label></p>
                <p><label>Details: <textarea type="text" id="details" maxlength="114" ></textarea></label></p>              
                <input class="button" type="button" id="addRecord" onclick="" value="Add Record"/>
            </fieldset>
        </form>             

            <div class="sort">
                <h3>Sort</h3>
                <button class="button" id="sortByName">By Name</button>
                <button class="button" id="sortByAge">By Age</button>
                <br/><button class="button" id="reset">Reset Details</button>
                <br /><br />
            </div>
        </div>
        <section>
            <div id="employeeRecords">

            </div>
        </section>

    </div>  

    <script src="../js/employee_script.js"></script>
</body>
</html>

и вот мой Javascript:

var employees = [];



//--------------------------------------------------------------------------------------------------------------

function Person(name, age, pos, dtls, img){

    this.fullName = name;
    this.employeeAge = age;
    this.position = pos;
    this.details = dtls;

    this.avatarSrc = img;

        this.createProfile = function(){
        var profile = document.createElement("div");
        profile.className = "profileStyle";
        var avatar = document.createElement("img");
        avatar.src = this.avatarSrc;
        avatar.alt = this.fullName();
        profile.appendChild(avatar);
        var profileTxt = document.createElement("p");
        profileTxt.innerHTML = "<b>" + this.fullName() +
        "</b><br />" + this.age + 
        "</b><br />" + this.pos + 
        "</b><br />" + this.dtls;
        profile.appendChild(profileTxt);
        return profile;
        }

    employees.push(this);


}




for(var i=0; i < staff.length; i++){
document.getElementById("staff_list").appendChild(staff[i].createProfile());

}


//-----------------------------------------------------------------------------------------------------------



function compareNames(a, b){
    var nameA = //TODO - needs to refer to the employee name
    var nameB = //TODO - needs to refer to the employee name
    var result = 0;
    if (nameA < nameB){
        result = -1;
    }
    else if(nameA > nameB){
        result = 1;
    }
    return result;
}


//--------------------------------------------------------------------------------------------------------------

function sortName(){

}


//--------------------------------------------------------------------------------------------------------------

function sortAge(){

}


//--------------------------------------------------------------------------------------------------------------


function addRecord(){


}




//--------------------------------------------------------------------------------------------------------------


function writeRecords(){




//--------------------------------------------------------------------------------------------------------------



function resetArray(){

}






//--------------------------------------------------------------------------------------------------------------



function arrayButtons(){

}

Я понимаю, что, вероятно, много простых ошибок и чего-то не хватает, но у меня действительно проблемыпонимая это,

С уважением

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...