객체 목록에서 문자열을 찾을 수 있는지 확인하고 싶습니다.underscore.js _ 문자열과 객체의 경우
this.props.value
의 문자열은 "apple, peach"이고 this.state.list
은 개체 목록이며 각 개체는 키 - 값 쌍을 가지고 있습니다. this.state.list.name
에 "사과, 복숭아"가 있는지보고 싶습니다.
Underscore.js의 문서에서 : _.where(list, properties)
과 나는 list
으로 문자열을 입력 할 수 있다고 생각하지 않습니다. 객체 목록에 문자열이 있는지 어떻게 확인할 수 있습니까?
render() {
fruits = this.props.value # "apple, peach"
newFruits = _.where(this.props.value, this.state.list) # I want to see if "apple, peach" is found in the list of fruits in state, and if so, re-assign those values into newFruits
return (
<div>
<p>{newFruits}</p>
</div>
)
}
표시 할 수있는 코드는 무엇입니까? –
@MikeBrant 편집되었습니다. – patrickhuang94