HTML:
<div class="parent">
<input></input>
<button></button>
</div>
<div class="siblings">
<p class="children"></p>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('button').click(function(){
if($(this).siblings('input') != ""){
var addTo = $(this).siblings('input').val();
$(this).parent('parent').siblings('siblings').children('children').html(addTo);
}
});
Run Code Online (Sandbox Code Playgroud)
为什么不起作用?我想从输入中获取值,并替换内容p
.
我使用vuetify布局,我想在右侧制作按钮,但我发现align-end
哪个是vuetify属性不起作用,我offset-xs9
用来制作按钮右侧,但按钮是中心v-flex
,如何使其结束?帮助谢谢
代码如:
<div id="app">
<v-app id="inspire">
<v-layout row wrap align-end>
<v-flex xs3 offset-xs9 align-end>
<div>
<v-btn primary dark>Normal</v-btn>
</div>
</v-flex>
</v-layout>
</v-app>
</div>
Run Code Online (Sandbox Code Playgroud)
我非常困惑使用管道来处理写入流是否同步,因为我发现了有关回调来处理管道完成的问题
我只是想确保先完成写流,然后再执行其他fs.rename
操作,如:
(async function () {
await promiseTempStream({oldPath, makeRegex, replaceFn, replaceObj, tempPath})
await rename(tempPath, oldPath)
function promiseTempStream({oldPath, makeRegex, replaceFn, replaceObj, tempPath}) {
return new Promise((res, rej) => {
const writable = fs.createWriteStream(tempPath)
fs.createReadStream(oldPath, 'utf8')
.pipe(replaceStream(makeRegex ,replaceFn.bind(this, replaceObj), {maxMatchLen: 5000}))
.pipe(writable)
writable
.on('error', (err) => {rej(err)})
.on('finish', res)
})
}
}())
Run Code Online (Sandbox Code Playgroud)
它可以工作,但是在读取管道文档后我感到困惑,因为它说
默认情况下,当源Readable流发出“ end”消息时,将在目标可写流上调用stream.end(),从而使目标不再可写。
所以我只需要
await fs.createReadStream(oldPath, 'utf8')
.pipe(replaceStream(makeRegex ,replaceFn.bind(this, replaceObj), {maxMatchLen: 5000}))
.pipe(fs.createWriteStream(tempPath))
await rename(tempPath, oldPath)
Run Code Online (Sandbox Code Playgroud)
要不就
fs.createReadStream(oldPath, 'utf8')
.pipe(replaceStream(makeRegex ,replaceFn.bind(this, replaceObj), {maxMatchLen: 5000}))
.pipe(fs.createWriteStream(tempPath)) …
Run Code Online (Sandbox Code Playgroud) 如果我设置原型值并制作两个实例
然后在一个实例中更新原型值
现在其他实例原型值没有更新,为什么?
代码是
var A = function() {
}
A.prototype.u = 2;
var a = new A();
var b = new A();
a.u = 4
alert(a.u) // 4
alert(b.u) // 2
Run Code Online (Sandbox Code Playgroud)
它是如此不合理,它的原型价值不是这个价值.对?
我想读取文件然后更改它through2
然后写入相同的文件,代码如下:
const rm = require('rimraf')
const through2 = require('through2')
const fs = require('graceful-fs')
// source file path
const replacementPath = `./static/projects/${destPath}/index.html`
// temp file path
const tempfilePath = `./static/projects/${destPath}/tempfile.html`
// read source file then write into temp file
await promiseReplace(replacementPath, tempfilePath)
// del the source file
rm.sync(replacementPath)
// rename the temp file name to source file name
fs.renameSync(tempfilePath, replacementPath)
// del the temp file
rm.sync(tempfilePath)
// promiseify readStream and writeStream
function promiseReplace (readfile, writefile) {
return new Promise((res, …
Run Code Online (Sandbox Code Playgroud) (function(){
test();
}());
function Class(){
this.prop = 'hi';
}
Class.prototype.mod = function(num){this.prop = num;}
function test(){
var c = new Class();
c.mod('now'); // it'll say it's not a function
alert(c.prop); // it's work
}
Run Code Online (Sandbox Code Playgroud)
我想将函数和类移出就绪函数以使代码清理并节省内存,但我发现类方法不起作用。
如果我将原型移动到测试功能,它会起作用,就像
(function(){
test();
}());
function Class(){
this.prop = 'hi';
}
function test(){
Class.prototype.mod = function(num){this.prop = num;}
var c = new Class();
c.mod('now'); // it's ok
alert(c.prop);
}
Run Code Online (Sandbox Code Playgroud)
为什么我必须将原型方法移动到测试或就绪功能?