我的问题有点幼稚,但在搜索到处后我找不到答案.
我有一个架构 user
name: {type:String},
relations: [{
entity: mongoose.Schema.Types.ObjectId,
year: {type:Number}
}]
Run Code Online (Sandbox Code Playgroud)
我想用relations.entity= R1 更新用户的年份
我可以用一个update函数更新它
var toupdate = {}
toupdate["relations.$.year"] = 1900;
User.update({'relations.entity': 'R1'},{"$set": toupdate},
function(err,results){
// console.log(results);
});
Run Code Online (Sandbox Code Playgroud)
虽然这很好用,但我想使用.save()方法,因为我已经在上面更新了其他字段.
User.find({_id:"myid"},function(err,user){
user.name = "my new name";
// find the relation matching the relations.entity = "R1"
user.save(function(err,results){
// send my results returned
});
})
Run Code Online (Sandbox Code Playgroud)
如何在调用之前编写逻辑save()?
我正在使用 nodemailer 使用以下nodemailer-express-handlebars插件发送电子邮件。我用这个{dead blog post}作为参考
代码正在编译welcome模板但没有使用layout
我的代码如下:
var nodemailer = require('nodemailer');
var mg = require('nodemailer-mailgun-transport');
var hbs = require('nodemailer-express-handlebars');
var config = {auth: {api_key: "key-xxx",domain: "mydomain.com}}
var nodemailerTransport = nodemailer.createTransport(mg(config));
var options = {
viewEngine: {
extname: '.handlebars',
layoutsDir: 'views/email/',
defaultLayout : 'layout',
},
viewPath: 'views/email/'
}
nodemailerTransport.use('compile', hbs(options));
nodemailerTransport.sendMail({
from: 'from@mydomain.com',
to: 'to@gmail.com',
subject: 'Welcome to the XXX',
template: 'welcome'
}, function (err, results) {
if (err) console.log('Error: ' + err);
else console.log('Response: ' …Run Code Online (Sandbox Code Playgroud) 我们正在开发一个将作为托管解决方案提供的应用程序。我对如何在不复制基本代码的情况下使用多个具有相同代码的站点感到惊讶。
例如:网站1:www.example.com和网站2:www.sample.com将在相同的代码上运行,但是具有不同的配置设置和不同的主题...就像我们在wordpress中运行自己的域名一样。
我想知道我该怎么做。
同样在数据库的情况下..最好是我为每个网站创建单独的数据库,或者将具有网站ID的相同数据库用作每个表中的列。
请帮助我。
[说明]它不是域别名。就像...这将是一项服务。在这里,将为不同的客户提供不同主题的相同域名的相同应用程序。类似于博客作者的工作..具有自己的域名,但博客应用程序相同
[技术]专门研究如何使用主机名来确定要使用的配置,我们正在使用PHP和MySQL
build-process multiple-domains multiple-databases application-design
这个问题听起来很基本,但是我无法弄清楚如何在VueJS中做到这一点。
我在HTML中有以下内容
<script>
var config = {'cols':4,'color':'red'}
</script>
<div id="app">
<mycomponent :config="config"></mycomponent>
</div>
var app = new Vue({
el: '#app',
data: {
// config: config // I do not want to pass this
}
})
Run Code Online (Sandbox Code Playgroud)
以下是用例:
data{ config:config }Vue对象那样传递它。<mycomponent :config="{'cols':4,'color':'red'}"></mycomponent>但是配置将非常长,这将是我的最后选择。有没有办法做到这一点?
我有大约100个元素,我试图用jquery创建一个动画.
<div class="box" id="a1"></div>
Run Code Online (Sandbox Code Playgroud)
我需要根据函数为每个元素添加特殊样式.
其中哪些在浏览器中呈现得更快:
添加css属性
$(this).css({'background-color':'#000'})
Run Code Online (Sandbox Code Playgroud)
或者添加课程
$(this).addClass("style1")
Run Code Online (Sandbox Code Playgroud)
更新 了我想添加的更多内容:
我有一个带有行网格的父组件,我正在使用 vuex 传递数据,因为我添加了一条新记录,我想在模式窗口中打开新添加的记录。我正在发出一个事件并使用第一条记录(索引 = 0)打开模态。问题是,由于它是使用 vuex“动作”添加记录的 ajax 调用,因此在添加记录之前发生发射。如何等到记录添加事件?或者有更好的方法吗?
下面是代码:
<!-- Grid Component -->
<grid>
<addrow @newrecordadded="openNewlyAddedRecord"></addrow>
<gridrow v-for="row in rows" :key="row._id"></gridrow>
</grid>
computed: {
rows(){
return this.$store.state.rows;
}
},
methods:{
openNewlyAddedRecord(){
this.openmodal(this.rows[0])
}
}
Run Code Online (Sandbox Code Playgroud)
我的 store.js
state: {
rows : []
}
Run Code Online (Sandbox Code Playgroud)
所以在addrow组件中,一旦用户点击提交表单,它就会分派到 vuex
methods:{
onsubmit(){
this.$store.dispatch('addrow',this.newrow);
this.$emit("newrecordadded");
}
}
Run Code Online (Sandbox Code Playgroud)
actions.js
addrow({ commit,state }, payload){
var url = "/add";
Axios.post(url,payload)
.then(function(response){
commit('addnewrow',response.data);
});
}
Run Code Online (Sandbox Code Playgroud)
mutations.js
addnewrow(state,payload){
state.rows.unshift(payload);
}
Run Code Online (Sandbox Code Playgroud)
或者我们可以传递一个回调函数来调度吗?
我正在尝试在bash脚本别名命令中添加自定义变量,但无法做到这一点
我在.bash_profile文件中添加了以下内容
alias mvdb='mv ~/dbs/aw ~/dbs/aw-$1'
Run Code Online (Sandbox Code Playgroud)
在命令行中,我尝试运行脚本
mvdb "2017OCT20"
Run Code Online (Sandbox Code Playgroud)
我希望将命名的文件夹aw重命名为aw-2017OCT20运行命令时的名称
我正在检查sails.js的ejs布局代码,看到了说的那条线 delete window.self
<% /* Delete the global `self` to help avoid client-side bugs.
(see https://developer.mozilla.org/en-US/docs/Web/API/Window/self) */ %>
<script>delete window.self;</script>
Run Code Online (Sandbox Code Playgroud)
我试图找到一个答案为什么我们会删除window.self但是找不到答案.添加此行的理由是什么?
编辑:代码存在于行号.137这里:https://github.com/mikermcneil/ration/blob/master/views/layouts/layout.ejs
javascript ×3
vue.js ×2
alias ×1
arguments ×1
bash ×1
browser ×1
function ×1
jquery ×1
mongodb ×1
mongoose ×1
nodemailer ×1
optimization ×1
performance ×1
rendering ×1
sails.js ×1
vuejs2 ×1
vuex ×1