2016-12-02 59 views
0

我有以下設置:ForerunnerDB爲什麼找不到我的標籤?

<!DOCTYPE html> 

<html> 
<head> 
<meta charset="UTF-8"> 
<title>Barebones todo</title> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script src="./js/dist/fdb-all.min.js" type="text/javascript"></script> 
<script src="./js/dist/fdb-autobind.min.js" type="text/javascript"></script> 
<script src="scrypt.js" type="text/javascript"></script> 
<script id="myLinkFragment" type="text/x-jsrender"> 
    <li data-link="id{:_id}">{^{:name}}</li> 
</script> 

</head> 
<body> 


<form onsubmit="addGoal(); return false;"> 
    <label for="goalinput">Enter goal:</label> 
<input type="text" id="goalinput"> 
    <input type="submit"> 
</form> 
<button type="button" onclick="retrieve()">Retrieve</button> 
<div id="p"></div> 

<ul id="myList"> 
</ul> 

</body> 
</html> 

和我scrypt.js文件:

var fdb = new ForerunnerDB(); 
var db = fdb.db("myDatabaseName"); 
var goalCollection = db.collection("goal"); 

function addGoal() { 
    console.log("addig goal..."); 
    var newgoalname = document.getElementById("goalinput").value; 
    console.log(newgoalname); 

    goalCollection.insert({ 
    name: newgoalname, 
    order: 99 
}); 

    }; 
function retrieve() { 
    var findings = goalCollection.find({}); 
console.log(findings); 


document.getElementById("p").innerHTML = findings; 


} 

goalCollection.link("#myList", "#myLinkFragment"); 

然後我收到和錯誤說服力:

FDB-autobind.min.js :1未捕獲ForerunnerDB [Collection]目標無法將集合綁定到目標選擇器「#myList」,因爲它不存在於DOM中!

我真的不明白這個問題,因爲很明顯有一個帶有myList ID的UL標籤。 我想也許jquery沒有正確調用,但我使用了記錄的方式,所以它不應該是一個問題。我不知道可能導致問題的原因。

+0

的開發商,我不熟悉ForerunnerDB,但我沒有看到你等到DOM加載完畢。嘗試將您的'