首页  >  问答  >  正文

展示完整的 JSON 数据,而非仅限于单个元素

<p>这是我的json的样子。我想要在模态框中显示我点击的元素的数据。</p> <pre class="brush:php;toolbar:false;">[{ "id": 1, "companyName": "test", "image": "https://mmelektronik.com.pl/wp-content/uploads/2017/10/Insert-logo.jpg.png", "location": "Warsaw", "salary": "10000", "skill": "Junior", "tags": "test", "jobDescription": "test", "title": "UI Designer" } ] 现在我想要访问jobDescription并在模态框中显示它。</pre> <pre class="brush:php;toolbar:false;">b-modal(hide-footer="", :id="id") template(#modal-title="") | 信息 .d-block.text-center p {{ 在这里想要jobDescription }} b-button(variant="primary") 应用</pre> <p>这是我打开模态框的方式。</p> <pre class="brush:php;toolbar:false;">openModal(item) { this.offer = item; this.$bvModal.show(this.id); }</pre>
P粉771233336P粉771233336414 天前566

全部回复(1)我来回复

  • P粉879517403

    P粉8795174032023-09-02 11:46:50

    v-for用于循环遍历一组数据,这不是你想要的。假设id是你的json中的标识符,尝试这样做:

    b-modal(hide-footer="", :id="id")
          template(#modal-title="")
            | 信息
          .d-block.text-center
          p() {{ offers[id].jobDescription }}
            b-button(variant="primary") 申请
    

    如果你将选定的id存储为数据变量,你可以将其放在计算属性中:

    computed: {
      selected() {
        return this.offers[this.id].jobDescription;
      }
    }
    

    (编辑:我没有意识到你发布了你的json,我之前的回答是针对数组的)

    回复
    0
  • 取消回复