REACT我因为“无法读取未定义的属性'map'”而发芽

时间:2019-12-14 05:13:35

标签: javascript reactjs

import urllib.parse

def search_keyword(engine_name, query_string):
    # Store formats for each search engine with placeholders
    url_format = {
        "yahoo": "https://us.search.yahoo.com/search?p=__QUERY__&fr=yfp-t&fp=1&toggle=1&cop=mss&ei=UTF-8",
        "google": "https://www.google.com/search?safe=strict&sxsrf=ACYBGNQKbsRTGVazpquHLRnglPuOj1xW9w%3A1576297488275&source=hp&ei=EGT0XcCLDoj4abrUjcAF&q=__QUERY__&oq=__QUERY__&gs_l=psy-ab.3..35i39j0i203l9.1236.2231..2801...1.0..0.56.247.5......0....1..gws-wiz.......0.LoDd2hNQIFQ&ved=0ahUKEwjA0-LepbTmAhUIfBoKHTpqA1gQ4dUDCAU&uact=5"
    }

    url = url_format[engine_name]
    # Make sure to handle the case where the dict does not contain engine_name (KeyError)

    # Format the input params for URL use
    query_key = "__QUERY__"
    query = urllib.parse.quote_plus(query_string)

    # Replace placeholders
    url = url.replace(query_key, query)

    print(url)

search_keyword("yahoo", "hello")
# https://us.search.yahoo.com/search?p=hello&fr=yfp-t&fp=1&toggle=1&cop=mss&ei=UTF-8

search_keyword("google", "this has spaces")
# https://www.google.com/search?safe=strict&sxsrf=ACYBGNQKbsRTGVazpquHLRnglPuOj1xW9w%3A1576297488275&source=hp&ei=EGT0XcCLDoj4abrUjcAF&q=this+has+spaces&oq=this+has+spaces&gs_l=psy-ab.3..35i39j0i203l9.1236.2231..2801...1.0..0.56.247.5......0....1..gws-wiz.......0.LoDd2hNQIFQ&ved=0ahUKEwjA0-LepbTmAhUIfBoKHTpqA1gQ4dUDCAU&uact=5

search_keyword("google", '"quoted text"')
# https://www.google.com/search?safe=strict&sxsrf=ACYBGNQKbsRTGVazpquHLRnglPuOj1xW9w%3A1576297488275&source=hp&ei=EGT0XcCLDoj4abrUjcAF&q=%22quoted+text%22&oq=%22quoted+text%22&gs_l=psy-ab.3..35i39j0i203l9.1236.2231..2801...1.0..0.56.247.5......0....1..gws-wiz.......0.LoDd2hNQIFQ&ved=0ahUKEwjA0-LepbTmAhUIfBoKHTpqA1gQ4dUDCAU&uact=5

search_keyword("google", "spec|@l ch@arac+3r$")
# https://www.google.com/search?safe=strict&sxsrf=ACYBGNQKbsRTGVazpquHLRnglPuOj1xW9w%3A1576297488275&source=hp&ei=EGT0XcCLDoj4abrUjcAF&q=spec%7C%40l+ch%40arac%2B3r%24&oq=spec%7C%40l+ch%40arac%2B3r%24&gs_l=psy-ab.3..35i39j0i203l9.1236.2231..2801...1.0..0.56.247.5......0....1..gws-wiz.......0.LoDd2hNQIFQ&ved=0ahUKEwjA0-LepbTmAhUIfBoKHTpqA1gQ4dUDCAU&uact=5

我一直在尝试解决未定义的地图,尽管我在实际解决它方面没有任何进展。在座的任何人至少有想法可以与我一起寻求解决方案?预先感谢

1 个答案:

答案 0 :(得分:1)

尝试使用此条件。

     <div className="BusinessList">
        {
          this.props.businesses && this.props.businesses.map(business => {
            return <Business business={business} key={business.id} />
          })
        }
      </div>