簡體   English   中英

從javascript變量渲染Jade / Pug

[英]Render Jade / Pug from javascript variable

最近和Pug(Jade)合作時遇到了一些麻煩。 我將陣列從背面發送到前端,然后在客戶端對其進行排序。

看起來像這樣:

potentials是我使用res.render('./myPage', {potentials})從背面發送到前端的對象的數組

script.

    $(document).ready(function() {
      $("#age-slider").change(function(){

        var slider = document.querySelector('#age-slider')
        var sliderInputs = slider.querySelectorAll('input[type=range]')
        var found_age = potentials.filter(v => v.age >= sliderInputs[0].value && v.age <= sliderInputs[1].value);
        console.log(found_age)

      })
    })
  if (found_age)
    span
      li
       found_age.username

所以我的排序工作正常,我可以在使用輸入時記錄我的值,但是現在如何在此哈巴狗頁面上呈現數組found_age呢? 我有的

謝謝你的幫助 !

經過一整夜的挖掘,這對我有用:

found_age = potentials.filter(v => v.age >= sliderInputs[0].value && v.age <= sliderInputs[1].value);
      console.log(found_age)
        document.getElementById('array-Filter').innerHTML = found_age.map((user) => {
            return `
            <li>${user.username}  ${user.age} years old from ${user.city}</li>
            `;
        }).join('');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM