我有包含列表的文档.让我们说他们是:
[
{
_id: 52b37432b2395e1807000008,
name: ListA,
order: 1,
desc: 'More about List A'
},
{
_id: 52b37432b2395e1807000009,
name: LISTB,
order: 2,
desc: 'More about List B'
},
{
_id: 52b37432b2395e180700000e,
name: LISTC,
order: 3,
desc: 'More about List C'
},
{
..
}
]
Run Code Online (Sandbox Code Playgroud)
现在我想使用批量更新来更改其订单字段.我有一个update_stage命令的JSON
var updated_stage = [{_id: '52b37432b2395e1807000008', order:2},{_id: '52b37432b2395e180700000e', order:1}, {_id: '52b37432b2395e1807000009', order:3}]
Run Code Online (Sandbox Code Playgroud)
现在我需要使用我拥有的新数组更新Mongoose中的LIST模型.我知道我可以使用批量更新更新具有相同值的多个文档
Model.update({ }, { $set: { order: 10 }}, { multi: true }, callback);
Run Code Online (Sandbox Code Playgroud)
但我必须用不同的值来更新它们.我该怎么办?什么是最有效的方式?
我正在关注本教程:
https://devcenter.heroku.com/articles/s3-upload-node
使用NodeJS和Jquery将文件上传到Amazon s3.它适用于小图像和文件.但是它会产生XHR连接RESET错误.
我的CORS配置看起来完全像这样:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我认为这是一件容易的事,但我被困住了.这是代码:
在服务器上:
app.get('/api/currentuser',function(req,res){
User.findOne({ _id: req.currentUser.id },'name',function(err, user_details) {
if (err) {
return next(err);
}
if (user_details) {
res.send(user_details);
} else {
return next(new NotFound('Could not find any such user'));
}
});
});
Run Code Online (Sandbox Code Playgroud)
其中req.currentUser.id是从会话登录用户的id.所以如果调用/ api/currentuser方法,我得到一个响应
{
_id: 6161616161619hjksk
name: 'Devesh Kumar'
}
Run Code Online (Sandbox Code Playgroud)
现在在Backbone Marionette我使用模型和项目视图来显示用户名(他的_id和其他详细信息可能是)
骨干:
var CurrentUser = Backbone.Model.extend({urlRoot: '/api/currentuser' });
var CurrentUserView = Marionette.ItemView.extend({
template: "#current-user-view"
});
var currentuser = new CurrentUser();
var currentuser_view = new CurrentUserView({
collection: currentuserdetails
});
Completepp.rightRegion.show(currentuser_view);
Run Code Online (Sandbox Code Playgroud)
模板:
<%= name %>
Run Code Online (Sandbox Code Playgroud)
但是,有一个错误.它说名字没有定义.当我设置一个CollectionView和一个ItemView时,它可以正确渲染.但就我而言,不需要设置集合
作为一般问题,如何在Backbone中呈现此类应用程序级别视图?请帮忙
我尝试过LinkedIn Hopscotch和Intro.js来创建网站游览.但是它们都适用于静态页面/多个静态页面.
问题是我有一个单页面应用程序 - 其中大多数元素是在BackboneJS的帮助下动态创建的.在这种情况下 - Hopscotch和Intro.js都无法附加/等待动态创建的元素.
有没有可以这样做的图书馆.或者如果可以使用Hopscotch/Intro.js实现
var tour = {
id: "hello",
steps: [{
title: "Welcome!",
content: "Hey there! If you have just 2 minutes.",
target: document.querySelector(".list a"),
placement: "bottom"
}, {
title: "Create a new file",
content: "Create a new file",
target: document.querySelector("#page a"),
placement: "right",
onNext: function () {
$('.add-new a').click();
}
]
};
hopscotch.startTour(tour);
Run Code Online (Sandbox Code Playgroud)
对于前者:在Hopscotch上面我应该在$('.add-new a')后做什么.Click(); 打开一个模态窗口?
此网页中隐藏了一些元素.现在,如果我想找到隐藏的元素:
var node = jQuery('body')[0];
$(node).find(":hidden").remove();
Run Code Online (Sandbox Code Playgroud)
这将从主节点中删除隐藏的元素(这进一步改变了页面的布局).我想要做的是复制(克隆)未隐藏的元素.我正在尝试这个:
var clone = node.cloneNode(true);
$(clone).find(":hidden").remove();
Run Code Online (Sandbox Code Playgroud)
但这会删除克隆中的所有元素,而不仅仅是隐藏的元素(正如预期的那样,因为它不在dom中).从克隆中删除隐藏元素的最佳方法是什么?
我正在关注David Sulc关于Marionette的教程. http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/,以便学习扩展它.
现在让我们说每只猫都有一个名字,等级和类别
AngryCat = Backbone.Model.extend({
urlRoot: '/api/cats',
defaults: {
name: "New Cat Name",
category: "Red Cat"
}
});
Run Code Online (Sandbox Code Playgroud)
现在我想制作一个这样的复合视图:
第1类:红猫(03猫)
猫1
猫2
猫3
第2类:蓝猫(02猫)
猫X.
猫Y.
我怎样才能做到这一点.请帮忙!
backbone.js ×2
javascript ×2
jquery ×2
marionette ×2
node.js ×2
amazon-s3 ×1
batch-file ×1
css ×1
file-upload ×1
heroku ×1
html ×1
linkedin ×1
mongodb ×1
mongoose ×1