【发布时间】:2016-03-31 18:11:02
【问题描述】:
我想使用 Meteor 建立一个网站。这里只是我的html代码的一个例子。
<head>
<title>version_0.0.4</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> myTemplate}}
</body>
<template name="myTemplate">
<p id="&firstContent">Test to show my first content</p>
<p id="&secondContent">Test to show my second content</p>
<button type="button" id="save">Save content</button>
</template>
现在当有人按下保存内容时,我想在我的数据库中以“&”符号保存所有 id 的 innerHtml,效果很好。
/* ----- functions to include ----- */
function inputContent(collection, inhalt, alteID){
var id = collection.insert({
content: inhalt,
htmlId: alteID
});
return id;
}
Template.myTemplate.events({
'click #save': function () {
$(document).ready(function() { //Damit der Code erst ausgeführt wird, wenn der DOM geladen ist
var all = $('*[id^="&"]'); // Das "&" Zeichen ist der Identifier/ in all speichern aller elemente
console.log(all);
for (var i = 0; i < all.length; ++i) {
var item = all[i]; //Durch all iterieren
var idNeuesItem = inputContent(textList, item.innerHTML, item.id);//Enthält ID über Callback
console.log("Gespeichert :" + textList.findOne({_id: idNeuesItem}).content);
}
});
}
});
在我做完这些之后,我现在手动删除了 innerHtml 代码,这样我的 htmt 文件看起来像这样:
<template name="myTemplate">
<p id="&firstContent"></p>
<p id="&secondContent"></p>
<button type="button" id="save">Save content</button>
现在我希望可以在我的 id 中显示内容,以便用户看起来像以前一样,但内容来自数据库。我已经尝试过不同的版本,但没有一个有效。有人可以帮我吗?对不起,当这是一个nooby问题时,我对流星很陌生...... 感谢您的帮助
【问题讨论】:
标签: javascript html mongodb meteor meteor-helper