Home Ask Login Register

Developers Planet

Your answer is one click away!

Fred J. February 2016

Set default value if nothing is selected

The code below is expected to set headerLabel to "Select an Item" when the app first starts. Then once an item is selected, the headerLabel is expected to show the item name. I am able to get it to do the second parts but not the first. Thanks

  menuItems: [
    {menuItem: "task1"},
    {menuItem: "task2"},
    {menuItem: "task3"},
    {menuItem: "task4"},
    {menuItem: "task5"},
    {menuItem: "task6"},
    {menuItem: "task7"}

  'click .menuItem': function(event){
    Session.set('selectedItem', $(event.currentTarget).data('value'));

  'click .mainMenu': function(){
    alert("show the main menu ");

  headerLabel: function(){
    var selected = Session.get('selectedItem');
    if (selected === "") {
      headerLabel: "Select an item";
    } else {
      return selected;
<template name="mainMenu">
  <div class="container">
    <div class="row">
      <section class="col-xs-12">
        <div class="list-group">
          {{#each menuItems}}
            <a href="#" class="list-group-item menuItem" data-value={{menuItem}}>
              <img src="/abc.png">
              {{menuItem}} <span class="badge">&#x3e;</span>

<template name="header">
    <button class        


durrrr February 2016

Very simple actually:

<h3><label class="col-xs-8 text-center">{{#if headerLabel}}{{headerLabel}}{{else}}Default value{{/if}}</label></h3>

And in js code you can just do

  headerLabel: function(){
    return Session.get('selectedItem');

Post Status

Asked in February 2016
Viewed 2,986 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved