Meteor: How to initialize noUiSlider in Meteor?

爷,独闯天下 提交于 2019-12-12 02:18:44

问题


The js code to initialize it is easy to find:

Template.templateOne.onRendered(function(){
  noUiSlider.create(document.getElementById('slider'), {
    connect: "lower",
    range: {
      min: 0,
      max: 100
    },
    start: 50
  });
});

Could someone just give me the corresponding html? I tried just a div with id='slider' and I tried copying all the divs from the example sites via Chrome's inspect function. Neither worked :(


回答1:


First, you need to add the npm package.

meteor npm install --save nouislider

Create you slider container in your HTML file.

<template name="templateOne">
  <div id="slider"></div>
</template>

Then initialize it in your template's onRendered callback and be sure to input the package as well.

import noUiSlider from 'nouislider';

Template.templateOne.onRendered(function() {
   noUiSlider.create(this.$('#slider')[0], { 
     connect: "lower", 
     range: { min: 0, max: 100 }, 
     start: 50 
  }); 
});


来源:https://stackoverflow.com/questions/42593154/meteor-how-to-initialize-nouislider-in-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!