我Article在MongoDB数据库的集合中有这个现有文档:
[ { site: 'www.atlantico.fr',
date: '2014-05-27T11:10:19.000Z',
link: 'http://www.atlantico.fr/example.html',
_id: 538473817eb00f082f4803fc,
__v: 0} ]
Run Code Online (Sandbox Code Playgroud)
我想在Node.js中使用Mongoose为这个文档添加一个day有价值的新字段'example'.所以我这样做:
Article.update(
{ link: 'http://www.atlantico.fr/example.html'},
{ $set : {day : 'example'} },
function(err){
});
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,因为当我在那之后查询文档时,没有day出现新的字段......
在使用update或使用$setMongoose 时我一定犯了一个错误,但我找不到我的错误.
我错过了什么?谢谢!
我正在使用Select2(http://ivaynberg.github.io/select2/)将表单的输入字段(假设它的id是topics)处于标记模式,使用现有标记列表(允许用户)选择一些远程数据提供的标签或创建新标签.
array(list.json)是从我的服务器正确获取的.它有id和text字段,因为Select2似乎需要这些字段.它看起来像这样:
[ { id: 'tag1', text: 'tag1' }, { id: 'tag2', text: 'tag2' }, { id: 'tag3', text: 'tag3' } ]
Run Code Online (Sandbox Code Playgroud)
HTML文件中的脚本如下所示:
$("#topics").select2({
ajax: {
url: "/mypath/list.json",
dataType: 'json',
results: function (data, page) {
return {results: data};
},
}
});
Run Code Online (Sandbox Code Playgroud)
但输入字段显示"搜索",这意味着它无法使用该数组进行标记支持.
在选择二剧本,我知道我必须定义formatSelection和formatInput,但我没有得到他们应该如何在我的情况下工作,尽管我已阅读选择二文档...谢谢你的帮助!
我希望当选中表单(form1)的"是"单选按钮时,会出现一个新表单(form2),其中有两个单选按钮,其文本为"是"和"否".通过form1的"是"按钮中的"onclick"事件,我设法使用两个单选按钮显示新表单,但我无法显示其文本.由于单选按钮没有"innerHTML",我尝试将文本作为纯文本添加为"标签",但它不起作用.这是语法或逻辑中的问题(不可能与按钮同时创建文本)?谢谢您的帮助.
在我的HTML正文中,我有这个:
<form id="form1">
<input type="radio" id= "form1_no" value="no" checked>
<label for = "form1_no" >No</label>
<input type="radio" id= "form1_yes" value="yes" onClick= exam()>
<label for = "form2_yes" >Yes</label>
</form>
Run Code Online (Sandbox Code Playgroud)
功能考试()是:
<script type='application/javascript'>
function exam() {
var inputno = document.createElement("input");
inputno.type = "radio";
inputno.id = "form2_no";
inputno.value = "no";
inputno.onclick = function () {alert("I select No in Form 2")};
document.getElementById("form2").appendChild(inputno); // this is working
var inputyes = document.createElement("input");
inputyes.type = "radio";
inputyes.id = "form2_yes";
inputyes.value ="yes";
inputyes.onclick = function () {alert("I select …Run Code Online (Sandbox Code Playgroud)