我有一个JSON如下所示的文件:
{
"primaryBright": "#2DC6FB",
"primaryMain": "#05B4F0",
"primaryDarker": "#04A1D7",
"primaryDarkest": "#048FBE",
"secondaryBright": "#4CD2C0",
"secondaryMain": "#00BFA5",
"secondaryDarker": "#009884",
"secondaryDarkest": "#007F6E",
"tertiaryMain": "#FA555A",
"tertiaryDarker": "#F93C42",
"tertiaryDarkest": "#F9232A",
"darkGrey": "#333333",
"lightGrey": "#777777"
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其导入到.tsx文件中.为此,我将其添加到类型定义中:
declare module "*.json" {
const value: any;
export default value;
}
Run Code Online (Sandbox Code Playgroud)
而我正在这样导入它.
import colors = require('../colors.json')
该文件中,我使用的颜色primaryMain作为colors.primaryMain.但是我得到一个错误 - JSON
我究竟做错了什么?
我需要知道如何检查变量是数组还是对象
var arr = ['foo', 'bar'];
var obj = {
0: 'foo',
1: 'bar'
}
document.write('arr is an: ' + typeof arr + ', obj is an: ' + typeof obj)
// The result is always:
// arr is an: object, obj is an: object
Run Code Online (Sandbox Code Playgroud)
有什么办法可以区分这两种类型吗?
我试图每天减少一次变量.我为此编写了以下代码.
var counter = 10; //any value
setInterval(function() {
counter = counter - 1;
}, 86400000);Run Code Online (Sandbox Code Playgroud)
是否有更好或更有效的方法来实现同样的目标?
PS: - 我不想使用任何库.
我有一个内置使用create-react-app并托管在中netlify。
在此链接中,提到我需要为SPA编写重定向规则。
/* /index.html 200
Run Code Online (Sandbox Code Playgroud)
但是重定向到index.html是行不通的,因为没有使用该URL呈现任何视图。我也尝试过重定向到/喜欢
[[redirects]]
from = "/*"
to = "/"
Run Code Online (Sandbox Code Playgroud)
但这也不起作用。
我该如何进行全面重定向create-react-app?
这是我目前的代码
from twitter import *
t = Twitter(auth=OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET,
ACCESS_TOKEN, ACCESS_TOKEN_SECRET))
t.statuses.home_timeline()
query=raw_input("enter the query \n")
data = t.search.tweets(q=query)
for i in range (0,1000):
print data['statuses'][i]['text']
print '\n'
Run Code Online (Sandbox Code Playgroud)
在这里,我从所有语言中获取推文.有没有办法限制自己只用英语提取推文?
我从svg开始,我创建了以下标记.
<svg width="500" height="600" class="graph-container">
<g>
<rect x="150" y="190" height="50" width="200" rx="30" ry="30" nodeId="1" children="3" style="fill: none; stroke: rgb(68, 68, 68);"></rect>
<text x="250" y="220" text-anchor="middle" fill="#444" style="font-size: 24px;">root</text>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我通过d3js在较大的矩形中添加了一个小圆圈.
$( document ).ready(function() {
var node = d3.select('g');
var addchild = node.append("circle")
.attr("cx",320)
.attr("cy",210)
.attr("r",10)
.attr("class","addchild")
.style("fill","none")
.style("stroke","#444");
addchild.on("click", function() {
alert("on click");
});;
});
Run Code Online (Sandbox Code Playgroud)
但是click事件没有触发.
这是相同的jsfiddle.
var treeData = [{
"name": "Device",
"parent": "null"
}
];
var treeData2 = [{
"name": "Device",
"parent": "null"
}
];
$(document).ready(function() {
var margin = {
top: 20,
right: 120,
bottom: 20,
left: 120
},
width = 1260 - margin.right - margin.left,
height = 500 - margin.top - margin.bottom;
var i = 0,
duration = 750,
root;
var tree = d3.layout.tree()
.size([height, width]);
var diagonal = d3.svg.diagonal()
.projection(function(d) {
return [d.y, d.x];
});
var svg = d3.select("body").append("svg")
.attr("width", width + …Run Code Online (Sandbox Code Playgroud)我在我的项目中使用Konva JS.我在按钮点击上添加一个可拖动的形状.点击形状我需要获得形状的X和Y位置.getX和getY函数返回原始的X和Y.如何在拖动后更新X和Y.
示例代码如下.
var stage = new Konva.Stage({
container: 'canvas', // id of container <div>
width: 500,
height:300
});
jQuery("#add-shape").click(function(){
addShape();
});
var addShape = function(){
console.log("add shape");
var layer = new Konva.Layer();
var parentContainer = new Konva.Rect({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
width: 200,
height: 60,
cornerRadius: 10,
fill: '#ccc'
});
var smallCircle = new Konva.Circle({
x: stage.getWidth() / 2 + 200,
y: stage.getHeight() / 2 + 30,
radius: 15,
fill: "#F2784B", …Run Code Online (Sandbox Code Playgroud)我有一个getBookingStateObject调用另一个函数的函数getBookingStateButtons.反过来getBookingStateButtons调用另外两个函数linkButtons和sendEventButtons.
我正在尝试为上述场景编写测试.我的测试文件中有以下内容.
import {
getBookingStateButtons,
getBookingStateObject,
linkButtons,
sendEventButtons,
} from './bookingStates'
jest.mock('getBookingStateButtons', () => jest.fn())
jest.mock('linkButtons', () => jest.fn())
jest.mock('sendEventButtons', () => jest.fn())
it('calls getBookingStateButtons, linkButtons, sendEventButtons', () => {
getBookingStateObject({ aasm_state: 'created' }, '123')
expect(getBookingStateButtons).toHaveBeenCalledWith({
bookingId: '123',
events: [{ event: 'mark_requested', type: 'secondary' }],
links: [{ to: 'edit' }],
})
expect(linkButtons).toHaveBeenCalledWith({
to: 'edit',
type: 'secondary',
})
expect(sendEventButtons).toHaveBeenCalledWith({
event: 'mark_requested',
type: 'secondary',
})
})
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我收到以下错误:
Cannot find module 'getBookingStateButtons' from …
我正在尝试将网站图标添加到 Next js 项目中。该项目是使用 create-next-app 创建的。
favicon.png我的文件夹中有一个- 按照此处public提供的静态文件的说明进行操作
在我的布局文件中,我有以下代码:
<Head>
<title>{title}</title>
<meta charSet="utf-8" />
<meta
name="viewport"
content="initial-scale=1.0, width=device-width"
/>
<link rel="shortcut icon" href="../public/favicon.png" />
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
/>
</Head>
Run Code Online (Sandbox Code Playgroud)
布局文件位于components目录中且public位于根目录中。
但是,网站图标没有显示。我究竟做错了什么?