假设我有以下代码:
<html>
<head></head>
<body>
<div id="d">some text</div>
<script type="text/javascript">
var d = document.getElementByid('d');
var innerText = d.innerText || d.textContent;
innerText = 'new text';
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想用id ='d'更改div标签的文本值.不幸的是,上面的块代码不起作用,文本内容不会改变.
如果执行以下配方,它可以工作:
if (d.innerText) d.innerText = 'new text';
else d.textContent = 'new text';
Run Code Online (Sandbox Code Playgroud)
但我不喜欢上面的配方,因为它不紧凑.
你有什么建议为什么第一种方法不起作用?
我想在我的收藏中制作一个分页功能.如何找到具有"开始"和"限制"位置的文档并在单个查询中获取总文档编号?
我有以下数组值:
[
{
id: 1,
field: 'map'
},
{
id: 2,
field: 'dog'
},
{
id: 3,
field: 'map'
}
]
Run Code Online (Sandbox Code Playgroud)
我需要找出字段等于dog和的元素map.我知道我可以使用该_.filter方法并传递迭代器函数,但我想知道的是,是否有更好的解决方案可以传递搜索字段和可能的值.有人可以提供更好的方法吗?
编辑 ::
我可以使用以下方法:
_.where(array, {field: 'dog'})
Run Code Online (Sandbox Code Playgroud)
但在这里我只能检查一个条款
在官方的mongoose网站上,我发现如何通过数组中的_id删除嵌入式文档:
post.comments.id(my_id).remove();
post.save(function (err) {
// embedded comment with id `my_id` removed!
});
Run Code Online (Sandbox Code Playgroud)
我很感兴趣如何更新而不是删除这个?
我需要让用户下载他的文件并在响应完成后将其删除:
app.get('/download/:file', function (req, res) {
var filePath = '/files/' + req.param('file');
res.download(file);
fs.unlink(filePath);
});
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,fs.unlink可以比res.download更早地调用.
我需要在主域和所有子域之间共享会话cookie.我有两个基于expressjs框架的nodejs服务:
// example.local
...
app.use(session({
cookie: {
domain: "example.local"
}
, key: 'sid'
, secret: '[my secret]'
, saveUninitialized: true
, resave: true
, store: new RedisStore({
host: 'localhost',
port: 6379
})
}));
// blog.example.local
...
app.use(session({
// what should I write here? <---------
}));
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我应该在会话配置中写什么blog.example.local才能访问现有的cookie example.local?
编辑:正如@yeiniel建议的那样,我应该使用相同的配置,blog.example.local如下所示:
// blog.example.local
...
app.use(session({
cookie: {
domain: "example.local"
}
, key: 'sid'
, secret: '[my secret]'
, saveUninitialized: true
, resave: true
, store: new RedisStore({ …Run Code Online (Sandbox Code Playgroud) 我有以下示例:
var page = require('webpage').create(),
system = require('system');
if (system.args.length < 3) {
console.log('Usage: printheaderfooter.js URL filename');
phantom.exit(1);
} else {
var address = system.args[1];
var output = system.args[2];
page.viewportSize = { width: 600, height: 600 };
page.paperSize = {
format: 'A4',
margin: "1cm"
footer: {
height: "1cm",
contents: phantom.callback(function(pageNum, numPages) {
if (pageNum == numPages) {
return "";
}
return "<h1 class='footer_style'>Footer" + pageNum + " / " + numPages + "</h1>";
})
}
};
page.open(address, function (status) { …Run Code Online (Sandbox Code Playgroud) 我的iptables有以下logrorate配置:
/var/log/iptables.log {
daily
missingok
rotate 3
compress
notifempty
delaycompress
postrotate
/usr/sbin/service rsynclog restart > /dev/null
endscript
}
Run Code Online (Sandbox Code Playgroud)
当我尝试检查文件语法检查时出现以下错误:
sudo logrotate -vf /etc/logrotate.d/iptables
reading config file iptables
reading config info for /var/log/iptables.log
error: iptables:1 lines must begin with a keyword or a filename (possibly in double quotes)
Run Code Online (Sandbox Code Playgroud)
我的配置文件有什么问题?
假设我有像以下一样的对象:
var date = moment(new Date(2014,2,17,9,60));
Run Code Online (Sandbox Code Playgroud)
我怎么能没有时间克隆并获得新的momentjs对象?
我使用MongoDB/mongoose存储具有以下模式的博客帖子:
PostSchema = mongoose.Schema({
title: {type: String},
body: {type: String}
});
Run Code Online (Sandbox Code Playgroud)
现在我的帖子网址如下所示: http://www.example.local/posts/571f78d077b4454bafcfcced
我希望我的帖子包含如下的slug:
http://www.example.local/posts/571f78d077b4454bafcfcced/how-to-make-and-store-slug-for-title
所以我的问题是:
http://www.example.local/posts/571f78d077b4454bafcfcced到http://www.example.local/posts/571f78d077b4454bafcfcced/how-to-make-and-store-slug-for-title(nodejs,nginx,客户端).谢谢!
EIDT:我还发现在StackOverflow数据库viwer中用于id为503429的qoestion存储非slugged标题.那么,每当问题被要求时,SO是否计算出slu?