var getTempItem = id => ({ id: id, name: "Temp" });
Run Code Online (Sandbox Code Playgroud)
我知道上面的箭头功能相当于:
var getTempItem = function(id) {
return {
id: id,
name: "Temp"
};
};
Run Code Online (Sandbox Code Playgroud)
但我对以下内容感到有些困惑
const Todo = ({ onClick, completed, text }) => (
<li
onClick={onClick}
style={{
textDecoration: completed ? 'line-through' : 'none'
}}
>
{text}
</li>
)
Run Code Online (Sandbox Code Playgroud)
为什么函数参数包含在花括号中,而函数体只包含在括号中?
我将以下二维数组传递给我的树枝。
Array (
[0] => Array ( [restaurantname] => Pizza Hut
[restaurantaddress] => Union Place
[restauranttelephone] => 5555522255
[mstrestaurantstatusid] => 1
[restaurantid] => 1 )
[1] => Array ( [restaurantname] => The Coffee Bean
[restaurantaddress] => Maitland Crescent
[restauranttelephone] => 3333569855
[mstrestaurantstatusid] => 1
[restaurantid] => 2 )
)
Run Code Online (Sandbox Code Playgroud)
在我的树枝中,我只想打印餐厅名称。但我稍后会使用其他信息。我无法仅打印餐厅名称。请帮忙。谢谢你。
var Restaurant = React.createClass({
resPress: function (resId, resName) {
this.props.navigator.push({
name: 'viewMenu',
id: resId,
placeName: resName
});
},
render: function () {
var that = this;
return (
<View>
{this.state.place.map((item, i) => (<TouchableOpacity key={i} onPress={() => this.resPress(item.res_id, item.res_name)} ><Text>{item.res_name}</Text></TouchableOpacity>))}
</View>
)
}
});
Run Code Online (Sandbox Code Playgroud)
这完全没问题.我的问题是为什么我不能将值传递给'resPress',如下所述?
onPress={this.resPress(item.delivery_id, item.place_name)}
Run Code Online (Sandbox Code Playgroud)