Javascript TypeError:无法将未定义或null转换为对象材质表 { 标题:“商店”,字段:“仓库”, editComponent:props=>( { 那是一个州({ 所选存储:e.target.value }) let store=that.state.stores.find(item=>!that.state.selectedStores.includes(item.Adi) ) Object.keys(store.Urunler).map(函数(键,索引){ if(store.Urunler[key]){ 那是一个州({ 产品:that.state.products.push(store.Urunler[key]) }); } }) console.log(that.state.products) }} > {that.state.stores.map(项=>{ 返回{item.Adi} })} ) }, { 标题:“产品”,字段:“Urunler”, editComponent:props=>( { setState({selectedProducts:e.target.value}) }} > {/*AşAğ305; daki mapde hata veriyor.Objecteçevir*/} {that.state.products?Object.keys(that.state.products).map(函数(键,索引){ 返回{that.state.products[key].Adi} } ):null} )},
获取错误。我尝试在物料表行上执行多次选择,并使用第一次选择的Onchange更改第二次选择的数据。 我用的是firebase 当“store.Urunler”为null或未定义时,我会出现此错误。而且我的产品没有列在菜单项上,这意味着选择是空的,但state.products有数据 我怎样才能克服这个错误。我还想添加到Urunler,选择一个输入。我知道我应该为onChanges调用函数,但如果它起作用,我将在以后执行Javascript TypeError:无法将未定义或null转换为对象材质表 { 标题:“商店”,字段:“仓库”, editComponent:props=>( { 那是一个州({ 所选存储:e.target.value }) let store=that.state.stores.find(item=>!that.state.selectedStores.includes(item.Adi) ) Object.keys(store.Urunler).map(函数(键,索引){ if(store.Urunler[key]){ 那是一个州({ 产品:that.state.products.push(store.Urunler[key]) }); } }) console.log(that.state.products) }} > {that.state.stores.map(项=>{ 返回{item.Adi} })} ) }, { 标题:“产品”,字段:“Urunler”, editComponent:props=>( { setState({selectedProducts:e.target.value}) }} > {/*AşAğ305; daki mapde hata veriyor.Objecteçevir*/} {that.state.products?Object.keys(that.state.products).map(函数(键,索引){ 返回{that.state.products[key].Adi} } ):null} )},,javascript,reactjs,Javascript,Reactjs,获取错误。我尝试在物料表行上执行多次选择,并使用第一次选择的Onchange更改第二次选择的数据。 我用的是firebase 当“store.Urunler”为null或未定义时,我会出现此错误。而且我的产品没有列在菜单项上,这意味着选择是空的,但state.products有数据 我怎样才能克服这个错误。我还想添加到Urunler,选择一个输入。我知道我应该为onChanges调用函数,但如果它起作用,我将在以后执行{ { title: 'Stores', field: 'D
{
{
title: 'Stores', field: 'Depolar',
editComponent: props => (
<Select
name="Depolar"
type="text"
value={that.state.selectedStores}
multiple
input={<Input />}
onChange={e => {
that.setState({
selectedStores:e.target.value
})
let store=that.state.stores.find(item => !that.state.selectedStores.includes(item.Adi)
)
Object.keys(store.Urunler).map(function (key,index) {
if(store.Urunler[key]){
that.setState({
products:that.state.products.push(store.Urunler[key])
});
}
})
console.log(that.state.products)
}}
>
{that.state.stores.map(item=> {
return <MenuItem value={item.Adi}>{item.Adi}</MenuItem>
})}
</Select>
)
},
{
title: 'Products', field: 'Urunler',
editComponent: props => (
<Select
name="Urunler"
type="text"
value={that.state.selectedProducts}
input={<Input />}
multiple
onChange={e => {
that.setState({selectedProducts:e.target.value})
}}
>
{/* Aşağıdaki mapde hata veriyor. Objecte çevir*/}
{that.state.products ? Object.keys(that.state.products).map(function (key,index) {
return <div><MenuItem value={that.state.products[key].Adi}>{that.state.products[key].Adi} </MenuItem></div>
}
):null}
</Select>
)},
标题:“商店”,字段:“仓库”,
editComponent:props=>(
{
让odata=[]
这是我的国家({
所选存储:e.target.value,
产品:小田
})
let store=等待.state.stores.filter(项=>(
!that.state.selectedStores.includes(item.Adi))
);
console.log(存储)
这个.changeProducts(商店);}}
>
{that.state.stores.map(项=>{
返回{item.Adi}
})}
)
},
{
标题:“产品”,字段:“Urunler”,
editComponent:props=>(
{
setState({selectedProducts:e.target.value})
}}
>
{/*AşAğ305; daki mapde hata veriyor.Objecteçevir*/}
{that.state.products?Object.keys(that.state.products).map(函数(键,索引){
返回{that.state.products[key].Adi}
}
):null}
)
},
更改产品(商店){
var=这个;
Object.keys(存储).map(函数(键,索引){
让data=store[key].Urunler;
如果(数据){
那是一个州({
产品:{…that.state.products,…data}
});
}
})
}实际选择的存储使用on setstate和this.state,因此状态无法正常工作。应为其赋值,但更改不包括在内!that.state.selectedStores.includes(item.Adi)到that.state.selectedStores.includes(item.Adi)
{
title: 'Stores', field: 'Depolar',
editComponent: props => (
<Select
name="Depolar"
type="text"
value={that.state.selectedStores}
multiple
input={<Input />}
onChange={async e => {
let odata=[]
this.setState({
selectedStores:e.target.value,
products:odata
})
let store= await that.state.stores.filter(item => (
!that.state.selectedStores.includes(item.Adi))
);
console.log(store)
this.changeProducts(store);}}
>
{that.state.stores.map(item=> {
return <MenuItem value={item.Adi}>{item.Adi}</MenuItem>
})}
</Select>
)
},
{
title: 'Products', field: 'Urunler',
editComponent: props => (
<Select
name="Urunler"
type="text"
value={that.state.selectedProducts}
input={<Input />}
multiple
onChange={e => {
that.setState({selectedProducts:e.target.value})
}}
>
{/* Aşağıdaki mapde hata veriyor. Objecte çevir*/}
{that.state.products ? Object.keys(that.state.products).map(function (key,index) {
return <div><MenuItem value={that.state.products[key].Adi}>{that.state.products[key].Adi} </MenuItem></div>
}
):null}
</Select>
)
},
changeProducts( store){
var that=this;
Object.keys(store).map(function (key,index) {
let data=store[key].Urunler;
if(data){
that.setState({
products:{...that.state.products,...data}
});
}
})