私はForerunner To-doチュートリアル(http://www.forerunnerdb.com/tutorial/todoList.html)を見ていて、その結果を複製するのが難しいです。チュートリアルがNode上で実行されている可能性があることを理解しています。したがって、jsviewsや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
にこのJavaScriptコードを配置するようにしますが、まだエラーが発生します。
現時点では、最終製品セクションのコードを複製していますが、jsviewsとjqueryの依存関係はメインfdb-all.min.js
に追加しています。したがって、私のコードはチュートリアルの例と同じように見えますが、実行されません。
私はHTTP以外の環境でもこれを実行していますが、これは私のデスクトップで動作している別の例があるので問題ではありません。
EDIT:
それが助け場合は、これはそのまま私のコードです。
<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>
依存関係をどのくらい正確にロードしているかを表示すると役に立ちます。 'fdbは関数ではありません.'というエラーは、このスニペットからは出ることができません。なぜなら' fdb'はその中の関数として呼び出されないからです。あなたは 'typeof ForerunnerDB'を調べて、それが本当に定義されアクセス可能かどうかを調べることができます。 – Schlaus