来自模板的流星集合项目ID

时间:2016-10-21 17:20:23

标签: meteor

我正在从这样的集合中加载一系列模板。

边栏/ sidebar.html

<template name="Sidebar">
<ul id="slide-out" class="side-nav fixed grey darken-3">
    <li class="action-bar">
        <span id="add-new" data-target="modal-add" class="modal-trigger"><i class="small material-icons">add</i></span>
        <span id="save"><i class="small material-icons">note_add</i></span>
        <span id="rename"><i class="small material-icons">mode_edit</i></span>
        <span id="delete"><i class="small material-icons">delete</i></span>
        <span data-activates="slide-out" id="close" class="button-collapse close "><i class="small material-icons right">reorder</i></span>
    </li>
    <!-- Load save items-->
    {{#if Template.subscriptionsReady}}
        {{#each userSaves}}
            {{>ListItem}}
        {{/each}}
    {{else}}
        <p>Loading</p>
    {{/if}}
</ul>
<a href="#" data-activates="slide-out" style="display:none" class="button-collapse"><i class="material-icons">menu</i></a>
<!-- Modal form to add new simulator file -->
<!-- Modal Structure -->
<div id="modal-add" class="modal">
    <div class="modal-content">
        <h4>New Simulator</h4>
        {{> quickForm collection=saves id="newSimulator" type="insert" buttonClasses="modal-action modal-close btn waves-effect waves-light" buttonContent="Add"}}
    </div>
</div>
</template>

边栏/ Sidebar.js

import { Template } from 'meteor/templating';
import {  Saves } from '../../../../api/lists/SimulatorSaves.js';
import { Meteor } from 'meteor/meteor';

import './Sidebar.html';
import './SidebarListItem.js'

Template.Sidebar.onCreated(function() {
    var self = this;
    self.autorun(() => {
        self.subscribe('saves');
    })
});

Template.Sidebar.onRendered(function() {
    // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
    $('.modal-trigger').leanModal({
        ending_top: '25%', // Ending top style attribute
    });


});

Template.Sidebar.events({
    'click .button-collapse': function() {
        console.log("here")
        $(".button-collapse").sideNav();
    }
})

Template.Sidebar.helpers({
    saves: () => {
        return Saves;
    },
    userSaves: () => {
        return Saves.find({});
    }
});

我正在尝试从模板中获取集合项ID,因此我可以将其用作会话变量但我未定义。

边栏/ listItem.js

    import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';

import './SidebarListItem.html';

Template.ListItem.events({
    'click .file-link': () => {
        console.log(this._id);
    }
});

边栏/ listitem.html

<template name="ListItem">
    <li class="file-link"><a href="#!"><i class="material-icons">description</i><span>{{name}}</span></a></li>
</template>

如果有任何可以帮助我的话,那将非常感谢。

1 个答案:

答案 0 :(得分:0)

使用胖箭时,你没有这个;)