2013-05-13 87 views
1

我正在尝试向mobiscroll scroller添加第三个功能。首先是一些解释:我有4个定制的从“0”到“9”的轮子。用户可以在这里插入一个4位数字。mobiScroll - 点击额外按钮时重置轮子的值

除了标准的“取消”(“Abbrechen”)和“添加”(“OK”)按钮,我想实现一个复位(“Bestand”)按钮,将滚轮内的所有轮子设置为该值“0”。添加这个额外的按钮没有任何问题,但不幸的是添加了所需的功能。想要的功能只需将所有4个轮子的值重置为值“0”。继到目前为止我的代码:

初始化车轮....

var whl1 = {'1':'1', 
     '2':'2', 
     '3':'3', 
     '4':'4', 
     '5':'5', 
     '6':'6', 
     '7':'7', 
     '8':'8', 
     '9':'9', 
     '0':'0'}; 

var whl2 = {'1':'1', 
     '2':'2', 
     '3':'3', 
     '4':'4', 
     '5':'5', 
     '6':'6', 
     '7':'7', 
     '8':'8', 
     '9':'9', 
     '0':'0'}; 

var whl3 = {'1':'1', 
     '2':'2', 
     '3':'3', 
     '4':'4', 
     '5':'5', 
     '6':'6', 
     '7':'7', 
     '8':'8', 
     '9':'9', 
     '0':'0'}; 

var whl4 = {'1':'1', 
     '2':'2', 
     '3':'3', 
     '4':'4', 
     '5':'5', 
     '6':'6', 
     '7':'7', 
     '8':'8', 
     '9':'9', 
     '0':'0'}; 

var wheel = [{},{},{},{}]; 
wheel[0]['1000er'] = whl1; 
wheel[1]['100er'] = whl2; 
wheel[2]['10er'] = whl3; 
wheel[3]['1er'] = whl4; 

初始化的滚轮....(环内).......

$('#' + i +'').scroller({ 
    display: 'modal', 
    mode: 'clickpick', 
    lang : 'de', 
    headerText: function(value) { 
     //Some Stuff in here 
     }, 
    button3Text: "Bestand", 
    button3: function(){ 
     // this function doesn't work................ 
     $('#' + i +'').mobiscroll('setValue', ['0', '0', '0', '0']); 
    }, 
    formatResult: function(data) { 
    // some other stuff in here 
     }, 
    onSelect: function(valueText, inst) { 
    // some other stuff, too 
    }, 
    wheels: wheel, 
    height: 40 
    }); 

我已经尝试了很多方法来实现功能性,但没有任何工作....没有人有一个想法,我该如何解决这个问题?因为我已经花了很多时间来解决这个问题(整整两天...),我会非常感谢每一个反应或一点暗示......感谢提前,祝你有个愉快的一周!

+0

难道你也许还添加HTML代码来重现问题? – likeitlikeit 2013-05-13 14:01:58

回答

0

我认为在button3函数中,i的值总是相同的,它不记得它在循环内有什么值。

您可以通过使用jQuery的元素像这样的尝试循环:

HTML:

<input id="t1" class="mobiscroll" /> 
<input id="t2" class="mobiscroll" /> 
<!-- .... --> 

的Javascript:

$('.mobiscroll').each(function() { 
    var that = $(this); 

    that.mobiscroll({ 
     display: 'modal', 
     mode: 'clickpick', 
     lang : 'de', 
     headerText: function(value) { 
      //Some Stuff in here 
     }, 
     button3Text: "Bestand", 
     button3: function(){ 
      // this function doesn't work................ 
      that.mobiscroll('setValue', ['0', '0', '0', '0']); 
     }, 
     onSelect: function(valueText, inst) { 
      // some other stuff, too 
     }, 
     wheels: wheel, 
     height: 40 
    }); 
}); 
+0

Goog Morning dioslaka,非常感谢您的努力和您的快速发布......在尝试您的代码后,它一切正常!此外,您的回答听起来似乎合理且符合逻辑 - 您只需单独地在mobiscroll元素上循环播放....祝您周末愉快,我希望能像您一样帮助其他人参与此论坛.-) – 2013-05-14 07:36:23