【问题标题】:Meteor throwing error when trying to use bootstrap尝试使用引导程序时流星抛出错误
【发布时间】:2015-01-02 12:40:19
【问题描述】:

所以我试图将所有注册用户显示为主页顶部的选项卡(您可以关闭)。为此,我试图在这个 jisfiddle http://jsfiddle.net/4atm5abf/ 中回收代码。但是,我在尝试使用引导程序时遇到了错误/问题。

这是我的 header.html 的样子:

<template name="header">
    <header class="navbar">
        <div class="navbar-inner">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a class="brand" href="{{pathFor 'userSearch'}}">SocialStore</a>
            {{> listUsers}}
            <div class="nav-collapse collapse">
                <ul class="nav pull-right">
                    <li>{{>loginButtons}}</li>
                    <!-- <li>{{>user_tab}}</li> -->
                </ul>
            </div>
        </div>
    </header>
</template>

<template name="listUsers">
    <div class="container-fluid ">
        {{script}}
        <ul class="nav nav-tabs marginBottom" id="myTab">
            {{#each Allusers}}
            <li><a href="#profile"><button class="close closeTab" type="button" >×</button>{{username}}</a></li>
            {{/each}}
        </ul>
    </div>
</template>

这是我的 header.js 的样子:

Template.listUsers.helpers({
    Allusers: function() {
        return Meteor.users.find().fetch();
    },

    script: function() { 
    var currentTab;
    var composeCount = 0;
    //initilize tabs
    $(function () {
        //when ever any tab is clicked this method will be call
        $("#myTab").on("click", "a", function (e) {
            e.preventDefault();

            $(this).tab('show');
            $currentTab = $(this);
        });

        registerCloseEvent();
    });

    function registerCloseEvent() {

        $(".closeTab").click(function () {
            //there are multiple elements which has .closeTab icon so close the tab whose close icon is clicked
            var tabContentId = $(this).parent().attr("href");
            $(this).parent().parent().remove(); //remove li of tab
            $('#myTab a:last').tab('show'); // Select first tab
            $(tabContentId).remove(); //remove respective tab content
        });
    }

    //shows the tab with passed content div id..paramter tabid indicates the div where the content resides
    function showTab(tabId) {
        $('#myTab a[href="#' + tabId + '"]').tab('show');
    }
    //return current active tab
    function getCurrentTab() {
        return currentTab;
    }

    //this will return element from current tab
    //example : if there are two tabs having  textarea with same id or same class name then when $("#someId") whill return both the text area from both tabs
    //to take care this situation we need get the element from current tab.
    function getElement(selector) {
        var tabContentId = $currentTab.attr("href");
        return $("" + tabContentId).find("" + selector);
    }

    function removeCurrentTab() {
        var tabContentId = $currentTab.attr("href");
        $currentTab.parent().remove(); //remove li of tab
        $('#myTab a:last').tab('show'); // Select first tab
        $(tabContentId).remove(); //remove respective tab content
    }
}})

这是我的包文件的样子:

Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

insecure
standard-app-packages
iron:router
accounts-base
accounts-password
autopublish
accounts-ui-bootstrap-dropdown
jquery

我从包中删除了 bootstrap 并将 bootsrap-combined.min.css 添加到 /client/stylesheets 并将 bootstrap.min.js 添加到 lib/ 这是 jsfiddle 中的示例使用的两个文件。

这是我得到的错误:

=> Modified -- restarting.
W20141105-20:56:59.640(-8)? (STDERR) 
W20141105-20:56:59.642(-8)? (STDERR) /home/shubham/.meteor/packages/meteor-tool/.1.0.34.m1x0kw++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141105-20:56:59.643(-8)? (STDERR)                         throw(ex);
W20141105-20:56:59.643(-8)? (STDERR)                               ^
W20141105-20:56:59.644(-8)? (STDERR) ReferenceError: window is not defined
W20141105-20:56:59.644(-8)? (STDERR)     at app/lib/bootstrap.min.js:6:451
W20141105-20:56:59.644(-8)? (STDERR)     at app/lib/bootstrap.min.js:8:3
W20141105-20:56:59.645(-8)? (STDERR)     at /home/shubham/app/.meteor/local/build/programs/server/boot.js:168:10
W20141105-20:56:59.645(-8)? (STDERR)     at Array.forEach (native)
W20141105-20:56:59.645(-8)? (STDERR)     at Function._.each._.forEach (/home/shubham/.meteor/packages/meteor-tool/.1.0.34.m1x0kw++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141105-20:56:59.646(-8)? (STDERR)     at /home/shubham/app/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
[=================== ] 95% 31.7s

如果有人能告诉我如何完成这项工作,我将不胜感激。谢谢

【问题讨论】:

  • 引导 v2.2.2!耶稣已经过时了!至少使用 2.3.2 ...

标签: javascript jquery twitter-bootstrap meteor meteorite


【解决方案1】:

您是否尝试过从 CDN 获取 bootstrap.js,包括:

在您定义的任何 html 文件中?

这样你就可以判断它是否是引导程序和流星之间的交互,或者你的文件组织是否是问题(不确定将 bootstrap.js 放在你的 lib 文件夹中是否有效,或者你如何将它包含在你的 html 中)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    • 2019-04-22
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2015-01-05
    相关资源
    最近更新 更多