元素表单array.map不呈现

时间:2017-12-06 10:01:04

标签: javascript reactjs jsx

我正在尝试从我的状态(数组)渲染元素,但他们不希望在屏幕上渲染。如果我执行(function () { "use strict"; define([], function () { return ['constantService', '$timeout', '$window', '$rootScope', function (constantService, $timeout, $window, $rootScope) { return { restrict: 'EA', scope: false, link: function(scope, element, attr) { var w = angular.element($window); var tempScope = ''; console.log(scope.$parent.menu); scope.$parent.$watch('menu.showSubMenu', function(newValue, oldValue, scope) { console.log(newValue); if (newValue !== oldValue) { tempScope = scope; } }); w.bind('click', function(event){ var currentEle = $(event.target); //$rootScope.$broadcast('dropdown:close'); if(tempScope.menu && !(currentEle.hasClass('main-menu'))) { console.log(tempScope); tempScope.menu.showSubMenu=false; tempScope.$apply(); } }); } }; }]; }); }()); ,它会在控制台中记录我的名字。

console.log(b.name)

3 个答案:

答案 0 :(得分:4)

您需要退回地图:

sleep 10
plugins/search-guard-5/tools/sgadmin.sh -cd config/ -ts config/truststore.jks -ks config/kirk-keystore.jks -nhnv -icl

答案 1 :(得分:2)

您正在渲染方法中正确调用renderAllElements()函数。您似乎也正确地映射了您的数组变量,但是一旦完成映射,该函数不会返回任何内容。

只需为地图功能添加一个返回值,它应该有效:

renderAllElements() {
  return this.state.myData.map(b => {
      return(
        <div>
            <h4>{b.name}</h4>
        </div>
     )
  })
}

单线替代方案:

renderAllElements() {
  return this.state.myData.map(b => <div><h4>{b.name}</h4></div>);
}

答案 2 :(得分:1)

由于您已经使用了数组函数,因此您可以在不使用花括号的情况下重写它:

renderAllElements = () => (
    this.state.myData.map(b => (
        <div>
            <h4>{b.name}</h4>
        </div>
    ));
)

所以你不需要记住return语句:)