我有一个这样的Form组件:
var React = require('react'),
ReactRedux = require('react-redux');
var Form = React.createClass({
render: function(){
return (
<form onsubmit={this.onsubmit} action={this.props.action}>
{this.props.children}
</form>
);
},
// Method for parent component to call
submit: function() {
// do submission and return Promise so caller can take actions
},
onsubmit: function(e) {
// validation, make requests, etc
}
});
function mapStateToProps(state) {
return state;
}
module.exports = ReactRedux.connect(mapStateToProps)(Form);
Run Code Online (Sandbox Code Playgroud)
在我的组件渲染中,我有<Form id="paymentform" ref="form" action="/self">.
我不能这样做,this.refs.form.submit();因为this.refs.form指向连接器.据我了解,连接器是减速器更新道具的漏斗,但这样做不能触发调用submit.
用例基本上是从另一个动作提交表单,这将启动Form组件应该执行的操作,例如验证和XHR请求.
我能做到,React.findDOMNode(this.refs.form).submit() …
我的组件中有以下代码.当我更新某些东西时它会被调用,从而取代UI中的一堆东西.一切都在更新,除了用户看到的输入值.
let input = {
id: 'discount-' + geo + '-' + segment,
value: percentage,
disabled: applyToAll,
placeholder: '0.00'
};
cells.push(
<td key={'cell-' + geo + '-' + segment} className="discount-segment cfix">
<Text {...input} />
</td>
);
Run Code Online (Sandbox Code Playgroud)
这是<Text>返回,用的东西为清楚起见移除
return (
<div className={containerClasses.join(' ')} id={'field-container-' + id}>
{label}
<input
autoComplete="off"
type="text"
id={id}
ref="input"
{...extraProps}
name={id}
className={classes.join(' ')}
defaultValue={this.props.value}
onChange={this.props.onChange}
/>
</div>
);
Run Code Online (Sandbox Code Playgroud)
一切都很好.假设percentage值5在开始时,它将5在字段中显示.然后我做了一些更新percentage到50的事情.(控制台日志将在重新渲染时显示正确的数字).但是,该值仅5在UI中显示.我defaultValue在输入字段上使用,但我认为应该改变,因为整个事物从父级重新渲染.
编辑已
更新<Text>以设置value …
我有这样的代码:
_removeSelection : function(e, refocus) {
var thisObj = e.data,
lineItem = $(this).closest('li'),
templateData = lineItem.data('templateData');
thisObj.element.trigger('beforeRemoveSelection',[templateData]);
lineItem.remove();
thisObj._selection_items = $(thisObj._selections).find('li');
if ( ( refocus != 'undefined' && refocus === true ) || refocus == 'undefined') {
thisObj.refocus();
}
thisObj.element.trigger('toggleSelection');
thisObj.element.trigger('limitNotHit', [true]);
thisObj.element.trigger('removeSelection',[templateData]);
}
Run Code Online (Sandbox Code Playgroud)
一切都记录正常,似乎执行得很好.然而,在我的所有代码运行后,我得到一个例外:
"对象不支持属性或方法'getAttribute'"
所以我有一个循环调用函数X次,但它只运行一次完成函数.
编辑:循环触发单击运行该功能的元素.如果我使用firebug手动触发单击,它仍会抛出异常
编辑2:在jquery-1.6.2.js中的第4550行抛出异常
这样做lineItem[0].parentNode.removeChild( lineItem[0] );也会导致延迟异常.看起来@zzzz对于一些奇怪的缓存清理是正确的.
这仅在使用.trigger('click')时发生,而不是在实际单击元素时发生
我试过这个
phpunit --debug --filter /^complete/ feed.php;
出于某种原因,它说0测试.
如果我这样做phpunit --debug --filter /complete/ feed.php;会点击任何带有"完整"一词的功能
修改Command Land NPM应用程序。只有12行,我被卡住了。一旦我履行了诺言,该应用程序就会继续运行,而不是让我再次键入命令行(当然,直到cmd + C为止)。不知道要用谷歌找到自己的答案,所以希望下面的代码就足够了!
#! /usr/bin/env node
var MongoClient = require('mongodb').MongoClient;
var dbUrl = 'mongodb://localhost:27017/building';
console.log(process.argv);
MongoClient.connect(dbUrl)
.then(function(db){
console.log('connected to db!');
// I guess there is some command to run here?
// Promise resolution of sorts?
return;
});
Run Code Online (Sandbox Code Playgroud) 我正在使用webpack和babel.我有这样一个文件:
import React from 'react';
import ReactRedux from 'react-redux';
var Layout = React.createClass({
render(){
return (<div>Markup</div>);
}
});
function mapStateToProps(state, action) {
return state;
}
export default ReactRedux.connect(mapStateToProps)(Layout);
Run Code Online (Sandbox Code Playgroud)
出于某种原因,当我运行webpack时,在编译之后,它会运行此错误:Cannot read property 'connect' of undefined.不确定为什么它会在获取ReactRedux对象时失败.我的webpack配置是这样的:
var compiler = webpack({
entry: "./dist/runner.js",
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel', // 'babel-loader' is also a legal name to reference
query: {
presets: ['es2015', 'react']
}
}
]
},
devtool: 'source-map',
output: {
filename: "public/dist/bundle.js"
}
});
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的路由器文件:
import express from 'express';
import health from './health';
import surface from './surface';
const router = express.Router();
router.use('/health', health);
router.use('/surface', surface);
router.get('*', (req, res) => {
res.status(404);
res.json({
message: 'Uknown API endpoint'
});
});
export default router;
Run Code Online (Sandbox Code Playgroud)
在每个路由中,我使用NPM mysql包创建连接,然后在我打电话之前结束它res.send().IIRC创建连接并以每个查询结束它将是一个坏主意.
我试过做中间件,如:
router.use((req, res, next) => {
next();
mySingletonWrappingMysql.connection.end();
});
Run Code Online (Sandbox Code Playgroud)
鉴于我的路线正在做异步事情,endConnection呼叫过早发生.next是不是真的异步,所以我做不到await next,我甚至不确定这将是正确的方式/地方去做.此示例使用单例,因为我也不确定如何正确设置要在路径中使用的新实例.req.param似乎是一个不是最佳原因的选项,似乎是特殊查询param vars.
我正在尝试编写一个集成测试,该测试实际上需要 RTMP 流式传输到第 3 方服务。如何使用ffmpeg命令生成RTMP测试流?似乎是正确的答案,但我无法让它发挥作用。
作为基线,无需 RTMP 即可ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p test.mp4工作。
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -f flv rtmp://mylocation给我错误rtmp://mylocation: Input/output error
我应该注意该 URL 是有效的,否则我会收到一条错误消息,指出无法打开连接。
我也尝试过ffmpeg -f lavfi -i testsrc -pix_fmt yuv420p -f flv rtmp://mylocatiom。我读过,如果你不提供时间,它会永远持续下去,并认为我可能需要它来实现 RTMP 流。我遇到了同样的错误。
这是上次尝试的完整输出,添加了下面 @Gyan 建议的参数,以及详细的日志记录。
ffmpeg -loglevel verbose -f lavfi -i testsrc -pix_fmt yuv420p -f flv -c:v libx264 -g 50 rtmp://myhost:1935/identifier
ffmpeg version 4.1 Copyright (c) 2000-2018 the …Run Code Online (Sandbox Code Playgroud) 我有一些非常基本的代码,如下所示
#component file
import { html, LitElement } from 'lit';
import sheet from './css/styles.js';
export class CaiWc extends LitElement {
static styles = [sheet];
render() {
return html`
<h2>Hello World</h2>
<div>ITEM 1</div>
<div>ITEM 2</div>
<div>ITEM 3</div>
`;
}
}
Run Code Online (Sandbox Code Playgroud)
#styles.js
import { css } from 'lit';
export default css`
:root {
background-color: #0000cc;
color: #ff0000;
}
:host {
background-color: #ff0000;
color: #0000cc;
}
`;
Run Code Online (Sandbox Code Playgroud)
我不明白为什么没有显示背景颜色。当我的标记对于第三方 Web 组件更加复杂时,该 Web 组件的背景颜色将从:host. 如果我正确阅读https://developer.mozilla.org/en-US/docs/Web/CSS/background-color,则不会继承背景颜色。但是,如果默认是透明的,为什么不填充呢?
我想要show field status,jumlah,harga和total.
这是我的表结构
订购 {id_order, id_user, status}
订单详情 {id_order,jumlah, harga, total}
这是我的查询功能:
function shopstat($user_id) {
return $this->db->query("SELECT * from order_detail left join order on order_detail.id_order=order.id_order where order.id_user=$user_id");
}
Run Code Online (Sandbox Code Playgroud)
但我有一个错误的语法:
错误号码:1064
您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在'order on order_detail.id_order = order.id_order'附近使用正确的语法,其中order.id_user = 16'在第1行
我正在使用 JOI 14,似乎找不到升级到 17 的指南。我看到人们发布了有关 JOI 16 的类似问题,但最后一次更新是在 3 个月前。type根据我在如何在 Joi 中添加自定义验证器函数? 中看到的内容,它看起来不像16 中所要求的那样。。
我正在查看https://joi.dev/api/?v=17.3.0#extensions,其描述type是The type of schema. Can be a string, or a regular expression that matches multiple types.。
我尝试过这样的事情:
const snakeAlpha = joi => {
return {
type: 'object',
name: 'snakeAlpha',
base: joi.string().regex(/^[a-z]+(_[a-z]+)*$/)
};
};
const customJoi = Joi.extend({
type: 'object',
rules: {
snakeAlpha
}
});
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误:
ValidationError: {
"type": "object",
"rules": {
"snakeAlpha" [1]: "[joi => {\n …Run Code Online (Sandbox Code Playgroud) 在过去,我已经能够通过内联样式标记修改页面上的CSS.我知道这听起来很可怕,但它是为了自定义CSS写作而在处理一种所见即所得(虽然没有文字).
我曾经做过类似的事情:
tag.styleSheet.cssText = myrules;
我不知道究竟是什么时候,但是当我尝试这个时,IE开始说"无效的参数".真正的关键是,这样做tag.innerHTML = 'body {}'使Unable to set value of the property 'innerHTML': object is null or undefined不以任何其他浏览器发生.
编辑
要清楚我正在使用内联样式标记.我不是试图使用内联样式属性.
<style type="text/css" id="mytag"></style>
如何更改该标签的内部?
编辑2 请看这个小提琴:
看来我的tag.styleSheet.cssText解决方案与使用styleSheets属性完全相同.您可以注释掉cssText的最后一个定义,看它是否像@Teemu一样工作.所以现在我真的迷失了为什么它不适用于我的应用程序.如果有人有想法会破坏那些功能很棒的想法.与此同时,我将修补我的应用程序.