首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >了解先行者做的教程?

了解先行者做的教程?
EN

Stack Overflow用户
提问于 2016-07-16 20:32:30
回答 1查看 183关注 0票数 0

我正在查看先导教程(http://www.forerunnerdb.com/tutorial/todoList.html),在复制其结果时遇到了困难。我知道教程可能运行在Node上,因此jsview和jquery等依赖项可能不一定出现在索引示例页面上。不过,有些问题是我不明白的。例如,本节:

代码语言:javascript
复制
    <!-- Create a DB instance and store it globally -->
    <script type="application/javascript">
        window.fdb = new ForerunnerDB();
        db = fdb.db('test');

        // Ask forerunner to load any persistent data previously
        // saved for this collection
        db.collection('todo').load();
    </script>

导致错误,其中fdb不是函数,db没有定义。我确保在加载依赖项(即fdb-all.min.js )之后放置此fdb-all.min.js代码,但仍然会出现错误。

目前,我正在复制成品部分的代码,但是将jsview和jquery依赖项添加到主fdb-all.min.js中。因此,我的代码看起来与本教程中的示例相同,但没有运行。

我还在一个非HTTP环境中运行它,这不应该是一个问题,因为我有一个单独的示例,在我的桌面上运行时可以工作。

编辑

如果有帮助,这是我的代码逐字。

代码语言:javascript
复制
<html>
    <head>
        <title>My First ForerunnerDB Todo App</title>
    </head>
    <body>
        <!-- Include the whole forerunner system, bells, whistles and kitchen sink -->
<script src='http://www.forerunnerdb.com/js/forerunnerdb/dist/fdb-all.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://www.jsviews.com/download/jsviews.min.js'></script>
<script src='http://www.forerunnerdb.com/js/forerunnerdb/dist/fdb-autobind.min.js'></script>

        <!-- Create a DB instance and store it globally -->
        <script type="application/javascript">
            window.fdb = new ForerunnerDB();
            db = fdb.db('test');

            // Ask forerunner to load any persistent data previously
            // saved for this collection
            db.collection('todo').load();
        </script>

        <!-- Define a todo item template -->
        <script type="text/x-jsrender" id="todoItem">
            <li data-link="id{:_id}">
                <span>{^{:text}}</span>
            </li>
        </script>

        <!-- Create an element where our todo items will be output -->
        <ul id="todoList"></ul>

        <!-- Create our item entry form -->
        <form id="todoForm">
            <input id="todoText" type="text" placeholder="Enter todo item" />
            <input type="submit" value="Add Item" />
        </form>

        <!-- Use jQuery to hook the onsubmit of our form -->
        <script type="application/javascript">
            $('#todoForm').on('submit', function (e) {
                e.preventDefault();

                // Get the form's todo item text
                var itemText = $('#todoText').val();

                // Add the new item to ForerunnerDB's todo collection
                db.collection('todo').insert({
                    text: itemText
                });

                // Now we've added the item to the collection, tell
                // forerunner to persist the data
                db.collection('todo').save();
            });

            $('body').on('click', '#todoList li', function () {
                // Get the item id for the todo item clicked on
                db.collection('todo').remove({_id: $(this).attr('id')});
                db.collection('todo').save();
            });
        </script>

        <!-- Finally we tell forerunner to data-bind the collection to the todo list -->
        <script type="application/javascript">
            db.collection('todo').link('#todoList', '#todoItem');
        </script>
    </body>
</html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-16 21:07:47

我尝试了您的代码,问题是您包含了来自远程服务器的脚本(这不是cdn)。下载Forerunner脚本,并将它们包含在本地,一切都能正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38415364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档