我将此添加到我的页面:
<script type="text/javascript" src="{!URLFOR($Resource.kendoReact, 'kendoReact/kendo-dropdowns-react-wrapper.min.js')}"></script>
要访问我下载的剑道反应脚本的静态资源。
然后在页面中设置:
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>
);
}
}
但我明白了:ReferenceError: MultiSelect is not defined at MultiSelectContainer.render
。
我假设这就是我引入下拉反应 javascript 文件的方式。通过导入,您可以:import {MultiSelect} from 'blah blah path name';
,因此将定义 MultiSelect 。
是否可以像我一样引入 JS 文件,并确定 MultiSelect 是什么,以便定义它,就像在导入方法中一样?