this.name在Meteor中不起作用

时间:2014-02-04 10:34:15

标签: javascript meteor

我使用菜单项列表进行了示例示例。当我使用this.name单击菜单项列表时,我需要来获取菜单项的名称。这里` this.name不工作。所以请看下面的代码并建议我该怎么做?

模板代码:

 <template name="main">
   <div id="menu" style="float:left;">
      <div class="square {{ selected 0 }}">{{ square 0 }}</div>
      <div class="square {{ selected 1 }}">{{ square 1 }}</div>
      <div class="square {{ selected 2 }}">{{ square 2 }}</div>
      <div class="square {{ selected 3 }}">{{ square 3 }}</div>


      <div class="square {{ selected 4 }}">{{ square 4 }}</div>
      <div class="square {{ selected 5 }}">{{ square 5 }}</div>
      <div class="square {{ selected 6 }}">{{ square 6 }}</div>
      <div class="square {{ selected 7 }}">{{ square 7 }}</div>
  </div>
</template>

CSS:     .square {         游标:指针;         宽度:200像素;         高度:20像素;         border:4px solid#eeeee8;         border-radius:4px;         -moz-border-radius:4px;         保证金:4px;        // 向左飘浮;         text-align:center;         背景色:绿色; //#eeeee8;         font-size:20px;     }

JS代码:

var SPLASH = [
    'Home', 'Clients', 'Menu', 'About Us',
    'Contact Us', 'Others', 'Help', 'ETC',
]

Template.main.square = function (i) {
    //console.log("Selected square item="+i);
    return SPLASH[i];
};

Template.main.events({
    'click .square': function (evt, t) {

        evt.preventDefault();

        Session.set("selectedMenuName", this.name);
        console.log("***selectedMenuName=***" + this.name);

    }
});

1 个答案:

答案 0 :(得分:0)

您似乎将evt.target.innerHTML设置为var Name,但是您正在调用this.name'. 'Name !== name

此外,您不应该返回Session.get('selectedMenuName')而不是Session.equals吗?