如何从另一个函数调用函数?

时间:2017-10-11 23:57:04

标签: javascript function reactjs google-analytics

我有两个不同的谷歌分析功能。我试图从另一个函数调用一个函数。我收到的错误是handleAccounts = (response) => { var details = response.result.items; console.log(response); this.setState({ info: details }); details.map(function(x) { gapi.client.analytics.management.webproperties .list({accountId: x}) .then(this.handleProperties.bind(this)); //This is the line where I am getting the Error. }); } handleProperties = (response) => { // Handles the response from the webproperties list method. if (response.result.items && response.result.items.length) { // Get the first Google Analytics account var firstAccountId = response.result.items[0].accountId; // Get the first property ID var firstPropertyId = response.result.items[0].id; // Query for Views (Profiles). //queryProfiles(firstAccountId, firstPropertyId); console.log(response); } else { console.log('No properties found for this user.'); } } 。我不明白为什么?

webview.getSettings().setDomStorageEnabled(true);

1 个答案:

答案 0 :(得分:2)

如果从组件中调用这些函数,则需要在组件bindconstructorcomponentDidMount。绑定对于使'this'在回调中工作是必要的,因为类方法在React中没有默认绑定。