0

我正在寻求帮助:

http://jsfiddle.net/techii/9e2cJ/2/

这是对此的后续问题

但是因为这不是一个“带着你的问题来到这里,我们会为你解决”的网站,所以我特别有一个特别的问题

在上面的 jsfiddle 中,我使用了匿名滑块,并且对滑动/更改做出反应的函数应该过滤/匹配从 JSON 解析的餐馆。我正在尝试从我的四个滑块中提取值,但它们必须与它们各自的变量匹配,例如收集时的 ambienceSliderValue,以便我可以将它们与它们的 JSON 对应项进行比较(ambienceRating)

var refreshRestaurant = 
    $(".restaurant > div").each(function(){
            // Some code to extract things like spicyness, expensiveness
            // this part should maybe be in the JSON object constructor above to push data? Perhaps I should use .val(); instead?
            var ambienceRating = $(this).data("ambienceRating");
            var spicyRating = $(this).data("spicyRating");
            var garlicRating = $(this).data("garlicRating");
            var expensiveRating = $(this).data("expensiveRating");

               // Also some code to get the slider values...


            var isMatch = ambienceSliderValue <= ambienceRating && spicySliderValue <= spicyRating && garlicSliderValue <= garlicRating && expensiveSliderValue <= expensiveRating;
            $(this).toggle(isMatch);
    })

是我使用命名滑块的唯一解决方案吗?

4

1 回答 1

1

例如,我将显示回调函数中的变量更新:

HTML:

<div class="sliders">
    <div id='a'></div>
    <div id='b'></div>
    <div id='c'></div>
    <div id='d'></div>
</div>

JS:

$(function () {
  var vars={};
    $('.sliders div').slider({
        orientation: "horizontal",
        range: false,
        min: 0,
        max: 100,
        step: 1,
        value: 0,
        slide: refreshRestaurant,
        change: refreshRestaurant
    }); 

    function refreshRestaurant() {
     vars[this.id]=$(this).slider('value'); 
      console.log(vars);
    }
});

演示

于 2013-02-04T08:46:43.047 回答