我写了以下node.js文件:
var csv = require('csv-parser');
var fs = require('fs')
var Promise = require('bluebird');
var filename = "devices.csv";
var devices;
Promise.all(read_csv_file("devices.csv"), read_csv_file("bugs.csv")).then(function(result) {
console.log(result);
});
function read_csv_file(filename) {
return new Promise(function (resolve, reject) {
var result = []
fs.createReadStream(filename)
.pipe(csv())
.on('data', function (data) {
result.push(data)
}).on('end', function () {
resolve(result);
});
})
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我用Promise.all它来等待读取csv文件的两个操作.我不明白为什么,但是当我运行代码时,该行'console.log(result)'未提交.
我的第二个问题是我希望回调函数Promise.all.then()接受两个不同的变量,而其中每个变量都是相关承诺的结果.
我创建了2个原型实例,在原型中更改了一个函数,两个实例中都反映了变化(很棒).但是,当我通过删除函数修改原型时,该函数仍然存在于现有实例中.
function A() {
this.name = "cool";
}
A.prototype = {
howCool: function() {
return this.name + "er";
}
};
var a1 = new A(),
a2 = new A();
a1.name = "hot";
//line1
console.log(a1.howCool());
//line2
console.log(a2.howCool());
A.prototype = {};
//line3
console.log(a1.howCool());
//line4
var a3 = new A();
console.log(a3.howCool());Run Code Online (Sandbox Code Playgroud)
第1行和第2行按预期工作,在将原型设置为空后,第4行显示未定义的预期值.但是第3行仍然显示了函数定义.
我想在我的React应用程序中实现条带元素,看起来我可以使用一个很好的包装器.
但是,在文章中,作者说我们必须使用StripeProvider它并在根应用程序组件级别实现它 - 请参阅https://github.com/stripe/react-stripe-elements#getting-started
我需要使用自己的提供商连接到我的商店.如何在组件中使用两个提供程序?我甚至不确定这是不是一个好主意.
我当前的渲染方法如下所示:
render(
<Provider store={store}>
<App>
<SomeComponentInMyApp />
</App>
</Provider>,
document.getElementById('content-wrapper')
);
Run Code Online (Sandbox Code Playgroud)
我会将一个提供商包裹在另一个吗?
我已经完成了向过滤器添加多个关键字,但它们适用于包含两个关键字的列表中的项目.我想创建一个过滤器,列表中的任何项都可以匹配任一项或关键字.例如:
<input id="myInput" type="text" placeholder="Search any keywords">
<button id="mySearchBtn">search</button>
<ul>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
搜索输入:红绿
结果:
这是我的JQuery搜索功能,允许多个关键字.搜索功能仅生成项目的最后结果,但允许多个关键字.
$("#mySearchBtn").click(function() {
var value = $('#myInput').val().toLowerCase();
var values = value.split(" ");
var length = values.length
var cards = $(".card-col-wrapper")
for (j = 0; j < cards.length; j++) {
for (i = 0; i < length; i++) {
$(".card-col-wrapper").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(values[i]) > -1)
});
}
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<input id="myInput" type="text" placeholder="Search any keywords">
<button id="mySearchBtn">search</button>
<div class="card-col-wrapper">
<h3>one</h3>
</div>
<div …Run Code Online (Sandbox Code Playgroud)我想this.props.map在React组件上设置时触发一个函数- 使用ES6类语法定义:
export default class MapForm extends React.Component {...
目前,我正在使用componentDidUpdate()它,因为它在props设置时被触发- 但它也是由其他不相关的事件触发,这是不理想的.
另一方面,componentWillReceiveProps()在组件的生命周期的早期发生(在此时this.props.map返回undefined)
所以我想只在this.props.map设置时触发一个函数.
我错过了一个钩子吗?或者某种模式?
我有一些jQuery代码,+$(...)在很多地方使用.+在做的时候,代码在没有部件的情况下不起作用$(...).
我无法通过谷歌找到任何解释.如果可能的话,我会感激任何指导.
function calculate() {
var a = +$('#a').val(); // what is +$ ?
var b = +$('#b').val();
var c = b * 108.40;
//etc
}
Run Code Online (Sandbox Code Playgroud) 编辑:所以现在它不是随机的,它看起来总是无法从.css()方法执行(没有进行任何更改).仍然没有得到我可能犯的错误.
我试图用jQuery和animate.css动画删除div.
问题是这个动画依赖的字面上随机执行的事件和操作.
此代码运行以响应处理程序click内的a .on("click"...:
$('section').on('click', 'button', function() {
// Remove the selected card
$(this).closest('.mdl-card')
.addClass('animated zoomOut')
.one('animationend', function() {
empty_space = $('<div id="empty-space"></div>');
empty_space.css('height', ($(this).outerHeight(true)));
$(this).replaceWith(empty_space);
});
// everything is okay until now
// setTimeOut() doesn't always execute
setTimeout(function() {
console.log("test1");
// the following doesn't always happen...
$('#empty-space')
.css({
'height': '0',
'transition': 'height .3s'
// transitionend doesn't always fire either
})
.one('transitionend', function() {
$('#empty-space').remove();
console.log("test2");
});
}, 300);
// Upgrade the DOM for …Run Code Online (Sandbox Code Playgroud)javascript jquery css-transitions css-animations animate.css
我将尝试用简短的段落描述一个最小化的问题.
总之,我想用一些逻辑,或是从网页调用一些功能在我的电子应用在我的电子应用(我在实际包装为我的网页电子应用"壳").
假设我想在我的Electron应用程序中公开一个函数.说,
function printNumbers () {
console.log(1)
}
Run Code Online (Sandbox Code Playgroud)
请注意它应该位于我的电子代码中.
然后在运行我的应用程序后,我想从我的网页上调用此功能(单击我的网页中的一个按钮,该按钮从网站加载,然后在我的Electron App中打开一个新窗口).现在,我想我可以使用开发者控制台检查printNumber是否有效.
我已经检查了如何使用remote模块来调用电子内部的函数/模块.但我没有找到一种方法来调用我在电子代码库中编写的函数.
顺便说一句:我可以启用该nodeIntegration选项.
我想根据产品 ID 更改我的路由,这是动态的。
我使用冒号找到了变量的解决方案。
path: "/:product_id" component: ProductDetail
Run Code Online (Sandbox Code Playgroud)
我如何product_id在我的组件中使用。
难倒这个,肯定有一种优雅的方式来做到这一点,但不确定是什么。
我想要类似的东西:
let x = 5;
const p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 2000);
}).then(() => {
console.log(x);
});
x = 3;
// Print out 5 after 2 seconds.
Run Code Online (Sandbox Code Playgroud)
基本上,给定与上述类似的设置,是否有办法打印输出,'5'而不管x在异步超时期间的值是否更改?就我而言,这将是很难简单地通过x在resolve()。
javascript ×10
jquery ×3
reactjs ×3
ecmascript-6 ×2
node.js ×2
promise ×2
react-redux ×2
animate.css ×1
asynchronous ×1
bluebird ×1
closures ×1
electron ×1
prototype ×1
react-native ×1
react-router ×1
redux ×1