我试图将所选值从下拉菜单传递到handleSearch()
,然后将此传递到filterList()
。
但是,它无法达到filterList()
。
private handleSearch(e) {
let key = e.key;
let val = e.target.value;
let type = e.target.type;
let tname = e.target.name;
///code above
if (type == "select-one") {
let opt = [{ name: tname, value: val }]; //e.g. [{name:"Category",value:"abc"}]
debugger;
let page;
this.filterList(
this.state.searchvalue,
page,
this.state.selectVal ? this.state.selectVal : opt
);
///code below
/// I can read the data here
private filterList(query: string, ItemsPerPage = 10, options?) {
let category = "";
let users = "";
let orderby = "Title";
let order = "asc";
if (options) { // undefined
for (let i = 0; i <= options.length; i++) {
if (options.name == "Category") {
/// codes continue
<select name="Category" onChange={props.select}>
<option value="">All Category</option>
{cat.map(i => (
<option value={i}>{i}</option>
))}
</select>;
props.select定义为 父组件中的select = {this.handleSearch} 我错过了什么吗?
答案 0 :(得分:0)
我知道为什么> <我正在循环for循环。 因此
if (options.name == "Category") {
应该是
if (options[i].name == "Category") {