小编TA3*_*TA3的帖子

ECMAScript 6箭头功能

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)

为什么函数参数包含在花括号中,而函数体只包含在括号中?

javascript ecmascript-6 reactjs

2
推荐指数
1
解决办法
171
查看次数

如何在symfony 2中的树枝中打印数组中的值?

我将以下二维数组传递给我的树枝。

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)

在我的树枝中,我只想打印餐厅名称。但我稍后会使用其他信息。我无法仅打印餐厅名称。请帮忙。谢谢你。

php symfony twig

1
推荐指数
1
解决办法
2万
查看次数

通过在React Native中触发onPress将值传递给方法

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)

javascript reactjs react-native

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×2

reactjs ×2

ecmascript-6 ×1

php ×1

react-native ×1

symfony ×1

twig ×1