简体   繁体   English

从javascript变量渲染Jade / Pug

[英]Render Jade / Pug from javascript variable

I'm having some troubles while working with Pug (Jade) lately. 最近和Pug(Jade)合作时遇到了一些麻烦。 I'm sending an array from my back to my front and then I'm sorting it client-side. 我将阵列从背面发送到前端,然后在客户端对其进行排序。

It looks like this : 看起来像这样:

potentials is the array of objects that I'm sending to my front from my back with res.render('./myPage', {potentials}) 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

So my sort is working I can log my values when I'm playing with the inputs but how can I render my array found_age on this pug page now ? 所以我的排序工作正常,我可以在使用输入时记录我的值,但是现在如何在此哈巴狗页面上呈现数组found_age呢? What I have 我有的

Thanks for any help ! 谢谢你的帮助 !

After a long night of dig here's what is working for me : 经过一整夜的挖掘,这对我有用:

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