正确的方法来改变组件方法的实现?

时间:2015-04-01 18:06:12

标签: javascript reactjs ecmascript-6

我正在使用https://github.com/fmoo/react-typeahead来对某些文字进行自动完成。我想改变它的行为,以便它立即显示结果(服从它的maxVisible道具)。我非常确定我所要做的就是在getOptionsForValue方法中添加几行代码,但我不知道如何扩展组件以执行此操作。

我听说使用ES6风格的Javascript可能会有一些希望,所以我尝试了这个:

class CustomTypeahead extends TypeAhead {
    getOptionsForValue(value, options) {
        var result = [];
        if (value === '') {
            result = options;
        } else {
            result = fuzzy.filter(value, options).map(function(res) {
                return res.string;
            });
        }
        if (this.props.maxVisible) {
            result = result.slice(0, this.props.maxVisible);
        }
        return result;
    }
}

但是当在TypeAhead(使用React.createClass定义)中调用该方法时,我的自定义方法不会被调用。

0 个答案:

没有答案
相关问题