0

When we click on the family_type we need to get the materials. In the material_list helper loads only the last object i need to load the every family based on materials needed.

{{#each search_family_list}}
                                <li class="dropdown-submenu active"><a href="#" id="{{ family_id }}" class="family_type"><img src="" />{{ description }}</a>
                                    <ul class="dropdown-menu">

                                        {{#each material_list}}
                                            {{#each this}}
                                            <li><a href="" id="{{ material_id }}">{{ description }}</a></li>
                                            {{/each}}
                                        {{/each}}

                                    </ul>
                                </li>
                            {{/each}}

This my helper class

 Session.setDefault('materials_list',[]);

Template.header.events({
    "click .family_type": function (event, template)
    {

        Meteor.call('get_family_materials',event.target.id,function(err,result){
            if(err)
            {
                console.log(err);
            }
            else
            {
                Session.set('materials_list',result);
            }
        });
    }
});

Template.header.helpers({
    material_list: function ()
    {
        var family_id = this.family_id;

        console.log(Session.get("materials_list"));
        return Session.get("materials_list");
    }
});

Please help me.

2 Answers 2

1

Rather than,

Session.set('materials_list',result);

do

var oldList = Session.get("materials_list");
Session.set('materials_list',oldList.push(result));

Explanation Session.set() will set it to exactly what you tell it to. When you set future values, it doesn't care what the previous value was.

Sign up to request clarification or add additional context in comments.

3 Comments

Exception from Tracker recompute function: {{#each}} currently only accepts arrays, cursors or falsey values.
That would likely be due to the {{#each this}} inside of your {{#each materials_list}}. I'm guessing your materials_list is either an object or a string. Which is it?
Please provide the chat
1

Remove the {{#each this}}, and change the {{#each material_list.id}}

I don't really understand why are you using the {{this}}, but lets remove it an change the other {{each material}} tell me if works.

You can also remove the 3 {{each}} you have into 1 {{each}} since the drop down menu can be outside.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.