All members pages generated with Mustache have the same data informations of a single member

天涯浪子 提交于 2020-04-17 18:44:58

问题


I want to generate member pages with Mustache, based on Data from Firebase. Right now, I am able to generate a page for one member, but all other members have the same informations than this member... Let say I have 4 members, I should be able to have 4 different pages, but right now, only one can be found (one of the members... maybe the last document of the collection or the first document of the collection. )

Any ideas of what I should change?

Here is my javascript script:

The first part is where I display all members in one page. Each of the members has a "contact him" link that should bring to this member page.

function displayMembers(collec_name) {

    var theDiv = document.getElementById('show-all-members');

    firestore.collection(collec_name).get().then(snapshot => {
            snapshot.forEach(doc => {

// for each member, we display some information
// We have a "contact him" link, that shoud bring us in a Mustache generated page with all the member informations


                     .... Lot of code before ...

                var child_div_5_1 = document.createElement("div")
                child_div_5_1.setAttribute("class", "card-header-a");
                var h2_1 = document.createElement("H2")
                h2_1.setAttribute("class", "card-title-a");
                var a_1 = document.createElement("a")
                a_1.setAttribute("href", "#");
                var text_firstname = document.createTextNode(firstname);
                var br = document.createElement("br");
                var text_lastname = document.createTextNode(lastname);
                a_1.appendChild(text_firstname);
                a_1.appendChild(br);
                a_1.appendChild(text_lastname);
                h2_1.appendChild(a_1);
                child_div_5_1.appendChild(h2_1);
                var child_div_5_2 = document.createElement("div")
                child_div_5_2.setAttribute("class", "card-body-a");

// BELOW IS THE IMPORTANT PART

                var a_2 = document.createElement("a")
                a_2.setAttribute("href", "coach-informations.html");
                a_2.setAttribute("class", "link-a");
                a_2.oncomplete = displayMemberPage(doc.data());
                a_2.appendChild(document.createTextNode("Contact him"));

// I can't have a specific html page for each member. Each member has the same data content from one of the document of the whole collection.

                var span = document.createElement("span")
                span.setAttribute("class", "ion-ios-arrow-forward");
                a_2.appendChild(span);
                child_div_5_2.appendChild(a_2);


                 ... Lot of code after ... 

And here is the function displayMemberPage, which should generate the page with Mustache and the data of the member.

function displayMemberPage(firebase_data) {

var data = {

    FIREBASE_DATA_NAME: firebase_data.firstname + ' ' + firebase_data.lastname,
    FIREBASE_DATA_CITY: firebase_data.ville,
    FIREBASE_DATA_PROFILEPIC: firebase_data.profilepic,
    FIREBASE_DATA_EMAIL: firebase_data.email
    };

template = ` all html template `


var html = Mustache.render(template, data);
$('#idWhereIaddresult').html(html);
};

来源:https://stackoverflow.com/questions/60577282/all-members-pages-generated-with-mustache-have-the-same-data-informations-of-a-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!