我正在查看先导教程(http://www.forerunnerdb.com/tutorial/todoList.html),在复制其结果时遇到了困难。我知道教程可能运行在Node上,因此jsview和jquery等依赖项可能不一定出现在索引示例页面上。不过,有些问题是我不明白的。例如,本节:
<!-- 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环境中运行它,这不应该是一个问题,因为我有一个单独的示例,在我的桌面上运行时可以工作。
编辑
如果有帮助,这是我的代码逐字。
<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>发布于 2016-07-16 21:07:47
我尝试了您的代码,问题是您包含了来自远程服务器的脚本(这不是cdn)。下载Forerunner脚本,并将它们包含在本地,一切都能正常工作。
https://stackoverflow.com/questions/38415364
复制相似问题