How to access kendo-react widgets when accessing the react dropdowns javascript by script instead of import?

China☆狼群 提交于 2019-12-11 16:33:13

问题


I added this to my page:

<script type="text/javascript" src="{!URLFOR($Resource.kendoReact, 'kendoReact/kendo-dropdowns-react-wrapper.min.js')}"></script>

To access a static resource of the kendo react script I downloaded.

Then set this up in page:

class MultiSelectContainer extends React.Component {
            constructor(props) {
                super(props);
                console.log('Setting up multiselect', props.data);
                this.dataSource = new kendo.data.DataSource({
                    data: props.data,
                    sort: {
                        field: 'name',
                        dir: 'asc'
                    },
                    group: {
                        field: 'resourceType',
                        dir: 'desc'
                    }
                });
                this.placeholder = 'Filter By People...';
                this.enable = false;
                this.minLength = 3;
                this.enforceMinLength = false;
                this.tagTemplate = '<span class="selected-value" title="#:he.decode(data.name)#" style="color: white;">#:he.decode(data.alias)#</span>';
                this.template = $('#dropDownTemplate').html();
                this.dataTextField = 'searchName';
                this.dataValueField = 'value';
                this.filter = 'contains';
                this.autoClose = false;

                this.onChange = this.onChange.bind(this);
                this.onSelect = this.onSelect.bind(this);
            }

            onSelect = (e) => {
                //Erase what the user has typed after they make a selection
                e.sender.input.val('');
            }

            onChange = (e) => {
                console.log('MultiSelect Changing', e);
                var filteredDataSource = e.sender.dataItems();
                //Get selected pills of user filter multi-select, and set their background colors to specified user color (either bland grey, or user defined color)
                var selectedTags = $('.k-multiselect li.k-button');
                for (var i = 0; i < selectedTags.length; i++) {

                    if (selectedTags[i].parentNode.id == 'user-filter_taglist') {
                        //ownerIdArr.push(value[i]);

                        var tag = $(selectedTags[i]);
                        var item = $(tag.find('span.selected-value'));
                        for (var k = 0; k < filteredDataSource.length; k++) {
                            if (item[0].textContent === he.decode(filteredDataSource[k].alias)) {
                                tag.css({
                                    'background': filteredDataSource[k].tagColor,
                                    'width': '100px',
                                    'height': '30px',
                                    'font-size': '15px',
                                    'overflow': 'hidden',
                                    'text-overflow': 'ellipsis',
                                    'border-radius': '5px'
                                });
                            }
                        }
                    }
                }    
            }

            render() {
                return (
                    <div>
                        <MultiSelect
                            change={this.onChange}
                            select={this.onSelect}
                            dataSource={this.dataSource}
                            placeholder={this.placeholder}
                            value={this.values} />
                    </div>
                );
            }
        }

But I get this: ReferenceError: MultiSelect is not defined at MultiSelectContainer.render.

I am assuming this is how I am bringing in the dropdowns react javascript file. With import, you'd do: import {MultiSelect} from 'blah blah path name';, so MultiSelect would be defined.

Is it possible to bring in the JS file like I did, and establish what MultiSelect is so it is defined, like in the import method?


回答1:


I did kind of figure this out in case anyone might be trying to do something similar... (loading the react scripts in a script tag instead of import).

But, I had to do <window.KendoDropdownsReactWrapper.MultiSelect /> instead of just <MultiSelect />

This should translate to most kendo react scripts you try to load in with a script tag, their components should all be in window.



来源:https://stackoverflow.com/questions/49740869/how-to-access-kendo-react-widgets-when-accessing-the-react-dropdowns-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!