假设有一个对象:
const object = {
'foo': {
'bar': [1, 2, 3]
}
}
Run Code Online (Sandbox Code Playgroud)
我需要推4送到object.foo.bar阵列.
现在我这样做:
const initialState = Immutable.fromJS(object)
const newState = initialState.setIn(
['foo', 'bar', object.foo.bar.length],
4
)
console.log(newState.toJS())
Run Code Online (Sandbox Code Playgroud)
但我真的不喜欢它,因为我需要object.foo.bar.length在路径中使用它.在我的真实示例中,对象嵌套得更深,并且获取数组的长度看起来非常难看.还有另一个更方便的方法吗?
在避免冲突的范围内组织类的技术之一是扩展父类的类+添加一些后缀.例如:
<div class="a">
<div class="a__b">
<div class="a__c">
<span class="a__d">
Run Code Online (Sandbox Code Playgroud)
从不重复代码的考虑,在sass/scss文件中,可以在&符号的帮助下引用父代 - &所以上面的结构可以像这样实现:
.a{
&__b{}
&__c{}
&__d{}
Run Code Online (Sandbox Code Playgroud)
哪个被改造成:
.a__b {}
.a__c {}
.a__d {}
Run Code Online (Sandbox Code Playgroud)
但是当一个人需要得到这样css的结果时会出现困难:
.a:hover{
color: red;
}
.a:hover .a__b{
color: blue;
}
Run Code Online (Sandbox Code Playgroud)
由于主要思想不是重复选择器,因此会出现一个问题 - 有没有办法引用二级父级?我知道这&&不是一个问题,但有没有办法模拟双&符号行为?
.a{
&:hover{
color: red;
& __b { /* & -> .a:hover, but I need just .a */
color: blue;
}
}
}
Run Code Online (Sandbox Code Playgroud)
不是问题,.a重复:
.a:hover { //here
color: red;
.a__b { //here
color: blue;
}
}
Run Code Online (Sandbox Code Playgroud)
也不是问题 …
我正在使用jsPDF插件,该插件会生成PDF并将其保存到本地文件系统。现在在jsPDF.js中,有一些代码以blob格式生成pdf数据:
var blob = new Blob([array], {type: "application/pdf"});
Run Code Online (Sandbox Code Playgroud)
并进一步将Blob数据保存到本地文件系统。现在而不是保存,我需要使用plugin node-printer插件打印PDF 。
这是一些示例代码
var fs = require('fs'),
var dataToPrinter;
fs.readFile('/home/ubuntu/test.pdf', function(err, data){
dataToPrinter = data;
}
var printer = require("../lib");
printer.printDirect({
data: dataToPrinter,
printer:'Deskjet_3540',
type: 'PDF',
success: function(id) {
console.log('printed with id ' + id);
},
error: function(err) {
console.error('error on printing: ' + err);
}
})
Run Code Online (Sandbox Code Playgroud)
在fs.readFile()读取PDF文件,并生成原始缓冲区格式的数据。
现在,我想要将“ Blob”数据转换为“原始缓冲区”,以便可以打印PDF。
我有一个带有按钮的抽屉组件,可以打开这个抽屉。我想通过单击页面上除抽屉区域之外的任何地方来关闭抽屉。我试过这个代码。它适用于打开,但它不适用于关闭。
var Child = React.createClass({
render: function() {
return (
<div className="chatBar">
<div onClick={this.onClick} className="closeBTN">
<img src="../src/contents/images/svg/close.svg"/>
</div>
<Tab />
</div>
);
}
});
var ChatBar = React.createClass({
getInitialState: function () {
return { childVisible: false ,childInVisible: true ,};
},
render: function() {
return(
<div>
<div onClick={this.onClick} className="chatBTN">
<img src="../src/contents/images/svg/chat.svg"/>
</div>
{
this.state.childVisible
? <Child />
: null
}
</div>
)
},
onClick: function() {
this.setState({childVisible: !this.state.childVisible});
},
onClickClose: function(){
this.setState({childInVisible: !this.state.childInVisible});
},
});
export default ChatBar;
Run Code Online (Sandbox Code Playgroud) 我正在用来gulp-spritesmith生成我的精灵,但我面临一个问题:我希望某些生成的样式成为悬停规则的属性,而不是类选择器的属性。在鼠标悬停事件上添加类看起来很难看,我不认为它是一个解决方案。
例如:
.icon-sr_ext_icon_right {
background-image: url(/imgs/static/external_sprite.png);
background-position: -300px -100px;
width: 50px;
height: 50px;
}
.icon-sr_ext_icon_right_hovered {
background-image: url(/imgs/static/external_sprite.png);
background-position: -222px -200px;
width: 50px;
height: 50px;
}
Run Code Online (Sandbox Code Playgroud)
成为:
.icon-sr_ext_icon_right {
background-image: url(/imgs/static/external_sprite.png);
background-position: -300px -100px;
width: 50px;
height: 50px;
}
.icon-sr_ext_icon_right:hover{
background-image: url(/imgs/static/external_sprite.png);
background-position: -222px -200px;
width: 50px;
height: 50px;
}
Run Code Online (Sandbox Code Playgroud)
这是我的 gulp 任务代码:
gulp.task('external_sprite', function() {
var spriteData =
gulp.src(paths.external.sprite)
.pipe(plugins.debug( { title: "Processing image for external sprite:" } ) )
.pipe(plugins.spritesmith({
imgName: 'external_sprite.png',
imgPath: '/imgs/static/external_sprite.png',
cssName: 'external_sprite.css' …Run Code Online (Sandbox Code Playgroud) 我想访问html文件并使用node.js获取id的元素,这是我的html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Diagram </title>
<script>
function generatePNG (oViewer) {
// some other code
reader.onloadend = function() {
base64data = reader.result;
var image = document.createElement('img');
image.setAttribute("id", "GraphImage");
image.src = base64data;
document.body.appendChild(image);
}
}, "image/png", oImageOptions);
return sResult;
var sResult = generatePNG (oEditor.viewer);
});
</script>
</head>
<body >
<div id="diagramContainer"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想document.getElementById("GraphImage").src用node.js 来搞定 .我发现我可以使用cheerio或jsdom访问DOM带有node.js,所以我尝试使用以下代码cheerio:
var cheerio = require('cheerio'),
$ = cheerio.load('file.html');
Run Code Online (Sandbox Code Playgroud)
但我没有找到允许我image.src从html文件中获取的指令,就像这条指令:document.getElementById("GraphImage").src
我尝试了两种方法,
1.
const wrapper=shallow(<ActiveConversation />)
wrapper.setProps({activeConversation:c,agent:a});
expect(wrapper.prop('messagesList')).to.equal(messagesList);
Run Code Online (Sandbox Code Playgroud)
2.
const wrapper=shallow(<ActiveConversation messagesList={messagesList}
agent={agent} contactFormState={d} tagSuggestions={t}/>);
Run Code Online (Sandbox Code Playgroud)
但是这两个道具仍未定义
Chrome 是否依赖操作系统在桌面上提供拼写检查?此处说明在移动设备上确实如此。但是对于桌面,它只是说明拼写检查默认在本地生成。
<!doctype html>
<html>
<body>
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type='file' name="image">
<br>
<input type="submit" value="submit">
</form>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer({ dest: 'uploads/',
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
} });
router.post('/upload', upload.single('image'), function(req, res){
res.send("Uploaded");
});
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
我有这个使用multer模块上传图像的基本代码.但是当文件上传时,它会生成一些随机名称,甚至可以删除文件扩展名.它只是说'文件'类型.那么如何将图像名称与扩展名保持一致.
我正在尝试使用材料ui创建加载状态指示器.但我想要对话框的背景颜色,none也想调整高度.但我无法通过他们提供的样式选项来做到这一点.有解决方案吗
现在它看起来像..
代码看起来像这样:
<Dialog
open={true}
style={{width: '200px', marginLeft: '40%', backgroundColor: 'transparent'}}
title= 'Loading'
titleStyle={{paddingTop: '0px', paddingLeft: '45px', fontSize: '15px', lineHeight: '40px'}}
>
<RefreshIndicator
style= {{display: 'inline-block'}}
size={50}
left={50}
top={30}
loadingColor="#FF9800"
status="loading"
/>
</Dialog>
Run Code Online (Sandbox Code Playgroud) 在你投票之前,我已经阅读了很多问题而且对我没有帮助.alert即使输入类型中存在值,我的Javascript 也会返回null.
这是代码: -
<script>
if (document.getElementById('p0002') != null) {
var str = document.getElementById("p0002").value;
}
else {
var str = null;
}
alert(str);
</script>
<input type="hidden" name="p0002" id="p0002" value="1" >
<input type="hidden" name="p0003" id="p0003" value="0" >
<input type="hidden" name="p0004" id="p0004" value="2" >
Run Code Online (Sandbox Code Playgroud)
它总是回归null.控制台中的错误说:
未捕获的TypeError:无法读取null的属性"value"
从最近1小时开始尝试修复它.这有什么不对?
我想合并两个数组并在图表上显示它们但不能这样做.请显示绘制该类型图表的正确语法.如果someobdy可以提供一个jsfiddle链接,那么对我的理解会更好.谢谢.
$(function () {
var name = ['chrome','firefox','opera'];
var data = [11.22,81.54,6];
var final = [name,data];
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares January, 2015 to May, 2015'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: "Results",
colorByPoint: true, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用两个文本参数创建一个函数,第二个参数应具有默认值“ en”(这是一个本地化参数)。
CREATE FUNCTION nav.getpathtext_new(path text, locale text DEFAULT "en") RETURNS json AS
$BODY$DECLARE
-- function code here ...
RETURN array_to_json(_toJson);
END$BODY$
LANGUAGE plpgsql VOLATILE NOT LEAKPROOF;
Run Code Online (Sandbox Code Playgroud)
而且我得到了错误:
错误:列“ en”不存在
第1行:... getpathtext_new(路径文本,区域设置文本DEFAULT“ en”)还原。
Run Code Online (Sandbox Code Playgroud)^
PostgreSQL版本是9.4。我究竟做错了什么?
javascript ×7
node.js ×3
reactjs ×3
css ×2
buffer ×1
cheerio ×1
dom ×1
enzyme ×1
express ×1
file-upload ×1
frontend ×1
gulp ×1
highcharts ×1
immutable.js ×1
jsdom ×1
jspdf ×1
material-ui ×1
multer ×1
postgresql ×1
printing ×1
sass ×1
sprite ×1
web-frontend ×1