小编Fai*_*een的帖子

为什么我的for循环不能处理我的Javascript属性?

我创建了这个对象及其属性:

var obj = {};

Object.defineProperty( obj, "value", {
  value: true,
  writable: false,
  enumerable: true,
  configurable: true
});

var name = "John";

Object.defineProperty( obj, "name", {
  get: function(){ return name; },
  set: function(value){ name = value; }
});
Run Code Online (Sandbox Code Playgroud)

那么我在它们上面调用for循环:

for ( var prop in obj ) {
  console.log( prop );
}
Run Code Online (Sandbox Code Playgroud)

根据我的教程,应该产生以下结果:

value
name
Run Code Online (Sandbox Code Playgroud)

但相反,它只显示价值.为什么姓名没有出现?

javascript ecmascript-5

5
推荐指数
2
解决办法
151
查看次数

如何在本机反应中使用变量“文档”?

我正在尝试捕获 SearchBar 组件之外的所有点击事件,以便我可以在单击时告诉下拉菜单关闭。我在网上查找了如何执行此操作的示例,我需要在 javascript 中使用全局变量“文档”。但是,似乎 react native 不支持这一点。有没有人知道使用“文档”变量或本机等效项的解决方法?

class Products extends Component {

    constructor(props) {
        super(props);

        this.setWrapperRef = this.setWrapperRef.bind(this);
        this.handleClickOutside = this.handleClickOutside.bind(this);
    }

    setWrapperRef(node) {
        this.wrapperRef = node;
    }

    handleClickOutside(event) {
        if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
          alert('You clicked outside of me!');
        }
    }

    componentWillMount() {
        this.props.dispatch(getProductList());
    }

    componentDidMount() {
        document.addEventListener('mousedown', this.handleClickOutside);
    }

    componentWillUnmount() {
        document.removeEventListener('mousedown', this.handleClickOutside);
    }

    render() {
        const {isLoading, products} = this.props.products;

        if (isLoading) {
            return <Loader isVisible={true}/>;
        }

        return (
            <View ref={this.setWrapperRef} style={styles.wrapper}>
                <Header/>
                <View style={styles.bodyWrapper}>
                    <ScrollView …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

5
推荐指数
1
解决办法
3708
查看次数

如何摆脱 React Native 中的 textInput 缩进(填充)?

我在我的 React Native 应用程序中使用 TextInput 并且占位符文本没有与其下方的边框对齐。占位符文本显示为距左侧缩进约 10 个像素。我们的 UX 不喜欢这样,并希望它与它下方的边框完全对齐。基本上,从左边开始,没有任何缩进。我已经对此进行了研究,但无法找到任何东西。有谁知道如何解决这一问题??

<View style={styles.emailInputBar}>
    {this.state.showUsernameLabel &&
        <Text style={styles.formLabel}>username</Text>
    }
    <TextInput
        underlineColorAndroid="transparent"
        style={styles.textInput}
        placeholder="username"
        placeholderTextColor="rgba(255,255,255,0.7)"
        autoCorrect={false}
        autoFocus={autoFocus}
        returnKeyType={'next'}
        autoCaptialize={'none'}
        keyboardType={'email-address'}
        enablesReturnKeyAutomatically={true}
        onFocus={() => this.onFocus()}
        onBlur={() => this.onBlur()}
        onSubmitEditing={() => this.passwordInput.focus()}
        onChangeText={(text) => this.handleUsernameChange(text)}
        value={email}
    />
</View>
Run Code Online (Sandbox Code Playgroud)

这是CSS:

passInputBar: {
    display: 'flex',
    flex: 1,
    backgroundColor: 'transparent'
},
textInput: {
    fontSize: 16,
    color: 'white',
    textAlign: 'left',
    width: '100%',
    flexDirection: 'row',
    paddingHorizontal: 10,
    borderBottomWidth: 2,
    borderBottomColor: '#FCE443',
    flex: 1,
    paddingTop:Platform.OS === 'ios' ? 7 : 0, …
Run Code Online (Sandbox Code Playgroud)

css reactjs react-native

5
推荐指数
3
解决办法
1万
查看次数

如何防止我的ImageBackground在React Native中调整大小?

当前,当您在登录页面上的文本字段内单击时,ImageBackground会调整大小或移动。我尝试将resizeMode设置为其所有可能的选项,但是它们都没有帮助。在不使用KeyboardAvoidingView的情况下如何防止这种情况发生?我尝试使用KeyboardAvoidingView,它不起作用,但也负面影响了我其他元素的宽度。

<ImageBackground source={require('../../assets/signinBG.jpg')} style={styles.backgroundImage}>
Run Code Online (Sandbox Code Playgroud)

样式:

backgroundImage: {
    flex: 1,
    backgroundColor:'rgba(0,0,0,0.45)',
    width: null,
    height: null
},
Run Code Online (Sandbox Code Playgroud)

这是我演示此行为的视频:

https://youtu.be/tVyq7mImecQ

react-native

5
推荐指数
1
解决办法
1154
查看次数

在javascript中是否有一种方法可以检测元素是否附加了任何事件?

我在页面上有一个链接列表,有时它们会附加事件,有时不会(它们只是不做任何事情).我想说,'如果这个元素没有事件处理程序(基本上它没有做任何事情),那么就为它添加一类禁用.我用谷歌搜索它,但没有找到任何检测事件处理程序的东西.有谁知道这样做的方法?

html javascript jquery

4
推荐指数
2
解决办法
2220
查看次数

如何使用document.referrer获取网址的各个部分?

我需要使用document.referrer以获取以前的URL我还需要能够获取URL的部分,如:

window.location.protocol
window.location.host
window.location.pathname
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何做到这一点document.referrer.有人有任何想法吗?

javascript

4
推荐指数
2
解决办法
9791
查看次数

如何强制反应原生内容忽略键盘?

我曾尝试同时使用 KeyboardAvoidingView 和 ScrollView 来防止我的内容在键盘存在时被压扁(向上推)。我曾尝试为我的行为使用填充、高度和位置,但没有任何效果。有人可以告诉我如何强制我的内容忽略键盘而不是被推起来吗?

return (
    <View style={{height: '100%', backgroundColor: '#D6D6D6', position: 'relative'}}>
        <View style={styles.wrapper}>
            <View style={{height:'100%', borderRadius: 7}}>
                <View style={styles.container}>
                    <ScrollView style={{borderRadius: 7}}
                        horizontal
                        showsHorizontalScrollIndicator={false}
                        scrollEventThrottle={10}
                        pagingEnabled
                        onScroll={
                            Animated.event(
                                [{nativeEvent: {contentOffset: {x: this.animVal}}}]
                            )
                        }
                    >
                        {imageArray}
                    </ScrollView>
                    <View style={styles.listViewContainer}>
                        <TouchableOpacity style={styles.listView} onPress={() => Actions.pop()}>
                            <View style={{flex: 1, flexBasis: 22}}>{listIcon}</View>
                            <View style={{flex: 2, flexBasis: 57}}><Text style={{color: '#fff'}}>List View</Text></View>
                        </TouchableOpacity>
                    </View>
                    <View style={styles.circleContainer}>
                        {circleArray}
                    </View>
                </View>
                <View style={styles.productsSection}>
                    <Text style={styles.title}>{prodDesc}</Text>
                    <Text style={styles.desc}>{prodBrand}</Text>
                    <Text style={styles.desc}>Item: {prodId || ''}</Text>
                    <Text style={[styles.desc, …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native

3
推荐指数
1
解决办法
4078
查看次数

如何更改 React Native (Android) 中 ActivityIndi​​cator 的颜色?

我需要将 ActivityIndi​​cator 的颜色更改为黑色,但仅限于应用程序的这个区域。我不想在其他任何地方改变它。有谁知道如何更改 Android 和 iOS 的颜色?

<ActivityIndicator 
    style={{position: 'absolute', right: 20, margin: 0, padding: 0}}
    animating={true}
    size='small'
/>
Run Code Online (Sandbox Code Playgroud)

android reactjs react-native

3
推荐指数
1
解决办法
5996
查看次数

为什么在React Native中“ Enter”键不会触发onKeyPress?

我在文本输入中添加了一个onKeyPress事件侦听器,以便当用户在电话键盘上单击完成或进入或“输入”时,它将调用我的searchProducts函数。我原本希望使用onSubmit类型的事件侦听器选项,但无法找到类似的内容,所以现在我只能简单地检查按下的每个键。当按下某个字符键(例如“ j”或“ x”)时,它将触发onKeyPress事件并调用我的searchProducts函数。但是,当我用鼠标单击完成或按键盘上的Enter键时,什么也没有发生。如何获取此信息以触发onKeyPress事件侦听器?

searchProducts = (e) => {
    if (e.nativeEvent.key == "Enter"){
        this.props.searchFunc(this.state.term);
    }
}

<TextInput 
    ref='searchBar'
    style={styles.searchInput} 
    placeholder={placeholder}

    onChangeText={this.searchSuggestions}
    onKeyPress={this.searchProducts.bind(this)}
    underlineColorAndroid="transparent" 
/>
Run Code Online (Sandbox Code Playgroud)

android react-native

2
推荐指数
1
解决办法
5217
查看次数

如何在lodash中使用_.once()函数?

我尝试在lodash中使用once函数,如下所示:

_.once(pageTwoSegmentEvent);

_.once(() => {
  pageTwoSegmentEvent();
})
Run Code Online (Sandbox Code Playgroud)

我也尝试过仅从 lodash 导入 Once 函数,而不是 _

once(pageTwoSegmentEvent);

once(() => {
  pageTwoSegmentEvent();
});
Run Code Online (Sandbox Code Playgroud)

但函数 pageTwoSegmentEvent 从未真正被调用。但是,如果我删除它所包装的一次函数并像平常一样调用它,那么它可以工作,但会被调用太多次。有谁知道如何让lodash的once函数发挥作用?

javascript lodash

2
推荐指数
1
解决办法
3754
查看次数

标签 统计

react-native ×6

javascript ×5

reactjs ×4

android ×2

css ×1

ecmascript-5 ×1

html ×1

jquery ×1

lodash ×1