在React Native中,textInput当你获得焦点时,你如何改变它的风格?说我有类似的东西
class MyInput extends Component {
render () {
return <TextInput style={styles.textInput} />;
}
};
const stylesObj = {
textInput: {
height: 50,
fontSize: 15,
backgroundColor: 'yellow',
color: 'black',
}
};
const styles = StyleSheet.create(stylesObj);
Run Code Online (Sandbox Code Playgroud)
我想改变焦点的背景颜色green.
这篇文档让我相信解决方案是这样的
class MyInput extends Component {
constructor (props) {
super(props);
this.state = {hasFocus: false};
}
render () {
return (<TextInput
style={this.state.hasFocus ? styles.focusedTextInput : styles.textInput}
onFocus={this.setFocus.bind(this, true)}
onBlur={this.setFocus.bind(this, false)}
/>);
}
setFocus (hasFocus) {
this.setState({hasFocus});
}
};
const …Run Code Online (Sandbox Code Playgroud) 我想做点什么
// WARNING: this code does not work, it's illustrative
query("#myBtn").onClick.listen((e) {
window.fire["foo"];
});
window.on["foo"].listen((e) => print("foo was here"));
window.on["foo"].listen((e) => print("and here"));
Run Code Online (Sandbox Code Playgroud)
可能吗?怎么样?我一直在Google上搜索几个小时,但我对编程很新,所以我真的不知道任何类似的关键字.
谢谢!:)
- 编辑:解决 -
以下是如何传递参数(编辑器会抱怨,但它有效)
List<String> myData = ["one","two"];
query("#myBtn").onClick.listen((e) {
window.on["foo"].dispatch(new CustomEvent("foo", canBubble: false, cancelable: false, detail: myData));
});
window.on["foo"].add((e) => print( e.detail[1] ));
Run Code Online (Sandbox Code Playgroud)
:-)
我正在玩两个优秀的库:js-csp和transducers.js试图绕着它们(和发生器).
我认为我对使用频道有一个很好的理解,但是当我决定将传感器(我还不太了解它)应用到它们时,我似乎无法使它工作.甚至这些例子都不适合我.
我使用的具体的transducers.js文件就是这个,对于js-csp,我编译了自己的(对于许多其他实验一直很好).基本上我用这个编译了一个文件:
import csp from 'js-csp';
window.csp = csp;
Run Code Online (Sandbox Code Playgroud)
使用browserify v.9.0.3和babel v.5.0.8.
这是我期望工作的一些示例代码:
// Make transducer
var xAdd10 = transducers.map(function (x) {
return x + 10;
});
// Make a channel, using the transducer
var ch = csp.chan(2, xAdd10);
// Put a number in the channel
csp.putAsync(ch, 1); // This throws an error
Run Code Online (Sandbox Code Playgroud)
我错过了什么?对我来说,这基本上是一样的我能为JS-CSP的文档中找到这里,和传感器在这里(2日至最后一颗子弹点).
csp库足以帮助抛出堆栈跟踪错误.看起来像这样:
error in channel transformer TypeError: xform.@@transducer/step is not a function
at Object.@@transducer/step (file:///Users/g/code/learning/generators-csp/js/lib/csp.js:1511:44)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用CKEditor的编辑功能,但是使用我自己的ui控件调用CKEditor的api来执行其命令.例如,
var style = new CKEDITOR.style({
element: 'span',
attributes: {
'style': 'font-size: 20px'
}
});
editor.applyStyle(style);
Run Code Online (Sandbox Code Playgroud)
设置所选文本的字体大小.
问题是我需要一种方法来了解当前所选文本的状态,以便我可以相应地更新控件.它大胆吗?然后粗体按钮应处于激活状态,单击它应删除粗体,而不是尝试再次添加.
有没有办法查询CKEditor当前所选文本的某些样式属性?就像tinymce.activeEditor.queryCommandValue('bold')在tinyMCE中如何工作一样.
我想知道是否可以只导入您需要的库的部分,而不是整个包.
举例来说明我的意思.
import {gt} from 'ramda';
console.log(gt(3, 2)); // true
Run Code Online (Sandbox Code Playgroud)
我保存它,并在其上运行browserify:
browserify a.js -t babelify -o b.js
Run Code Online (Sandbox Code Playgroud)
b.js现在在浏览器中运行; 但它长8432行!它导入了整个Ramda库,即使我只需要gt.js,_curry2.js,_curry1.js和isPlaceholder.js的内容.
如果相反,我像这样写上面的例子:
import gt from './node_modules/ramda/src/gt';
console.log(gt(3, 2)); // true
Run Code Online (Sandbox Code Playgroud)
然后,b.js变成98行长.
有没有办法(除了我刚才描述的那个)解决这个问题?
作为对这个问题的跟进(不是我),我需要用\\3n(用n代替我们正在替换的数字)替换id的前导数字.
一些例子:
"1foo" -> "\\31foo"
"1foo1" -> "\\31foo1"
"12foo" -> "\\31\\32foo"
"12fo3o4" -> "\\31\\32fo3o4"
"foo123" -> "foo123"
Run Code Online (Sandbox Code Playgroud)
下面是一个替换每个数字实例的解决方案,但我不知道足够的正则表达式,一旦它遇到非数字就停止.
function magic (str) {
return str.replace(/([0-9])/g, "\\3$1");
}
Run Code Online (Sandbox Code Playgroud)
...或者正则表达式是一个糟糕的方式去?我想这样做很容易,只需手动循环遍历字符串的每个字符.