我正在尝试测试连接的react组件,但是一旦包装了它,我就无法使用instance()获得它的实例,它返回null。对于未连接的组件,它确实会返回实例,有什么区别?如何获取已连接组件的实例?
it('connected component', () => {
const wrapper = mount(
<Provider store={store}>
<BrowserRouter>
<ConnectedComponent />
</BrowserRouter>
</Provider>
)
const myComp = wrapper.find(ConnectedComponent)
expect(myComp).toHaveLength(1) // passes
console.log(myComp.instance()) //null
})
it('non-connected component', () => {
const wrapper = mount(
<Provider store={store}>
<BrowserRouter>
<NonConnectedComponent />
</BrowserRouter>
</Provider>
)
const myComp = wrapper.find(NonConnectedComponent)
expect(myComp).toHaveLength(1) // passes
console.log(myComp.instance()) // prints the instancce
})
Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试将一些图像加载到流星项目中,在 onRendered 函数上,该函数还包括许多其他确实渲染的东西。
Template.Canvas.onRendered(function() {
this.blues = new Image();
this.blues.src = "bluesh.png";
}
Run Code Online (Sandbox Code Playgroud)
然后在还包含其他一些内容的自动运行函数中,有
this.ctx.drawImage(this.blues, this.dotsPaint[i].xCntr - this.radius, this.dotsPaint[i].yCntr - this.radius, this.radius * 2, this.radius * 2);
Run Code Online (Sandbox Code Playgroud)
当启动并触发绘画代码时,我收到此错误:
控制台错误:无法在canvasrenderingcontext2d上执行drawimage,提供的htmlimageelement处于损坏状态。
我在网上阅读了一些内容并看到了对图像使用 onload 函数的建议,所以我已经完成了
this.blues = new Image();
this.blues.src = "bluesh.png";
this.blues.onload = function () {
this.imageLoadCheck++;
console.log("test");
};
Run Code Online (Sandbox Code Playgroud)
onload 函数从未被触发。图像文件放置在与使用它的文件相同的文件夹中 project/imports/game 我还尝试将图像放置在导入画布代码的 main.js 的同一文件夹中,但这也不起作用。还尝试放置在不同的文件夹中并更改为 /..images/bluesh.png,我尝试将图像代码放置在 template.Canvas.onCreated 而不是 onRendered 上,但没有任何效果。在流星上加载图像有不同的方式吗?我错过了什么吗?
谢谢!
编辑:这是完整的控制台错误:
Exception from Tracker recompute function:
debug.js:41 Error: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the …
Run Code Online (Sandbox Code Playgroud) 我正在研究 NLP 问题。
我已经下载了用于嵌入层的预制嵌入权重。在嵌入层之前,我需要对当前采用句子字符串形式的数据集进行标记。我想使用与我的预制嵌入层相同的索引来标记它。
有没有办法用这种预制的字典初始化 Keras 标记器(tensorflow.keras.preprocessing.text.Tokenizer):{ 'the': 1, 'me': 2, 'a': 3 ..... }
所以它不会自己决定给每个单词哪个索引?
我在 HTML 页面中显示从文本文件中提取的一段文本,我希望考虑该文本文件中的换行符,因此我使用“空白:pre;”。另一方面,我想防止文本在其包含的 div 之外溢出,所以我添加了“word-wrap: break-word;” 不幸的是,这两个属性似乎不能一起工作(空格覆盖自动换行)。我怎样才能让这两个属性一起工作?
这是我尝试过的:
table {
width: 100%;
}
td {
text-align: center;
}
td > h4 {
display: inline
}
Run Code Online (Sandbox Code Playgroud)
<table>
<td>
<h4>Hello</h4><sup>World</sup>
</td>
</table>
Run Code Online (Sandbox Code Playgroud)
不幸的是,浏览器将"Hello"和"World"集中在一起.我怎样才能集中"你好"(但仍然有"世界"跟着它)?