尝试使用bootstrap时出现流星抛出错误

时间:2014-11-06 05:11:59

标签: javascript jquery twitter-bootstrap meteor meteorite

所以我试图在主页顶部显示所有注册用户作为标签(您可以关闭)。为此,我试图在这个jisfiddle http://jsfiddle.net/4atm5abf/中回收代码。但是,我在尝试使用bootstrap时遇到错误/问题。

以下是我的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>
&#13;
&#13;
&#13;

这是我的header.js的样子:

&#13;
&#13;
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
    }
}})
&#13;
&#13;
&#13;

这是我的包文件:

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

如果有人能告诉我如何完成这项工作,我真的很感激。感谢

1 个答案:

答案 0 :(得分:0)

您是否尝试过从CDN抓取bootstrap.js并包括:   

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

通过这种方式,您可以判断它是否是引导程序和流星之间的交互,或者您的文件组织是否存在问题(不确定它是否可以将bootstrap.js放在您的lib文件夹中,或者您是否包含它进入你的HTML)