如何在Node.js中将对象数组转换为字符串?

问题描述 投票:0回答:1
[
  RowDataPacket {
    House_Name: 'Merlin 5th Avenue',
    no_of_rooms: 6,
    Cost: 3400000,
    PropertyId: 2
  },
  RowDataPacket {
    House_Name: 'Presidential Building',
    no_of_rooms: 5,
    Cost: 3500000,
    PropertyId: 106
  },
  RowDataPacket {
    House_Name: 'GreenSlide Building',
    no_of_rooms: 4,
    Cost: 6300000,
    PropertyId: 107
  },
  RowDataPacket {
    House_Name: 'RabindraNath Building',
    no_of_rooms: 4,
    Cost: 5500000,
    PropertyId: 108
  },
  RowDataPacket {
    House_Name: 'CityView Apartment',
    no_of_rooms: 3,
    Cost: 4300000,
    PropertyId: 109
  }
]

我有这个要转换为字符串的对象数组,以便可以将它在get请求中传递给其他页面。如何将对象数组转换为字符串。数组中的对象数是动态的,可以更改。上面显示的数组只是一个示例。

还有其他方法可以在获取请求中传递数组吗?

我将数组传递到一个玉文件中,然后它调用一个get请求?

doctype html
html(lang='en')
  head
    meta(charset='UTF-8')
    title Property List
    link(rel='stylesheet', href='/stylesheets/prop-list-style.css')
    link(href='//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', rel='stylesheet')
    link(rel='stylesheet', href='/stylesheets/likeButton.css')

  body
    // partial:index.partial.html  https://picsum.photos/500/300/?image=10
    .main
      h1(data-text='Property List') Property List
      - var prop = props
         ul.cards
             for pip in prop
                li.cards_item
                    .card
                        .card_image
                            img(src='https://picsum.photos/500/300/?image=10')
                        .card_content
                            h2.card_title #{pip.House_Name}
                            p.card_text #{pip.no_of_rooms} BHK
                              a(href='/signIn/interested?id=#{pip.PropertyId}&cid=#{customerid}&values=#{properties}') 
                                i.like-button.fa.fa-2x.fa-heart-o(class='#{like}')
                            p.card_text Price: #{pip.Cost}
                            a(href='/signIn/readMore?id=#{pip.PropertyId}&cid=#{customerid}&values=#{properties}')
                                button.btn.card_btn Find Out More
             else 
                h2 No such property exist
    script(src='/javascripts/likebutton.js')

    // partial

#{properties}变量是保存数组的变量,并且是get请求的一部分。

javascript arrays node.js json pug
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.