2011-03-02 25 views
0

我有一个使用高速缓存的值,以显示给用户的MVC视图经由旁路值小部件

@Html.TextboxFor(x => x.SomeInteger, new { @class="selector" }); 

和类似的构造。

我的问题是,当我做到这一点

$(“.selector”).wijinputnumber({ 
    type: ‘numeric’, 
    minValue: 0, 
    decimalPlaces: 0, 
    showSpinner: true 
}); 

文本框中的值被设置为0,但(例如)的用户可能已投入4之前,我需要它来反映这一点。另外,我已经证实我的模型实际上在SomeInteger属性中有4个,所以不是这样。

有没有办法告诉wijinputnumber不设置初始值?

这里只是HTML和Wijmo/jQuery的一个完整的例子出现此问题:

<!DOCTYPE HTML> 
<html> 
<head> 
    <link href="http://cdn.wijmo.com/themes/rocket/jquery-wijmo.css" rel="stylesheet" type="text/css" /> 
    <link href="http://cdn.wijmo.com/jquery.wijmo-open.1.1.2.css" rel="stylesheet" type="text/css" /> 
    <link href="http://cdn.wijmo.com/jquery.wijmo-complete.1.1.2.css" rel="stylesheet" type="text/css" /> 
    <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js" type="text/javascript"></script> 
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.min.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/external/jquery.bgiframe-2.1.3-pre.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/external/jquery.glob.min.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/external/jquery.mousewheel.min.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/external/raphael-min.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/jquery.wijmo-open.1.1.2.min.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/jquery.wijmo-complete.1.1.2.min.js" type="text/javascript"></script> 
</head> 
<body> 
    <input type="text" class="correct" value="5" /> 

    <input type="text" class="notcorrect" value="10" /> 

    <script type="text/javascript"> 
     jQuery(document).ready(function($) { 
      $('.correct').wijtextbox();   

      $(".notcorrect").wijinputnumber({ 
      type: 'currency', 
      decimalPlaces: 2, 
      showGroup: true, 
      showSpinner: true 
      });    
     }); 
    </script> 
</body> 
</html> 

回答

0

事实证明,这是Wijmo一个bug目前,但从this post的工作如下:

$(“.selector”).each(function() { 
var n = $(this).val(); 
$(this).wijinputnumber(
{ 
type: ‘numeric’, 
minValue: 0, 
decimalPlaces: 0, 
showSpinner: true, 
value: n 
}); 
}); 
+0

该死的,我也应该在这里回答它!可能得到了信用。 ;)感谢发布答案哥们。 – Banzor 2011-03-30 17:06:47

1

你可以使用一个元素的VAL()函数来获得它的值

<script type="text/javascript"> 
    jQuery(document).ready(function($) { 
     $('.correct').wijtextbox();   

     $(".notcorrect").wijinputnumber({ 
      type: 'currency', 
      decimalPlaces: 2, 
      showGroup: true, 
      showSpinner: true, 
      value: $(".notcorrect").val() 
     });    
    }); 
</script> 

希望这可以帮助,

马特

+0

感谢您的建议。问题是我的真实世界的场景实际上有多个文本框,所以$(“。不正确”)是一个东西的数组,而不是一个单一的项目。 – Joseph 2011-03-03 02:12:30

+0

@Joseph:由于我无法编辑您的帖子!我更喜欢你自己的解决方案,但我很惊讶它被开发人员忽视了。 – 2011-03-03 09:19:59

+0

他们正在解决问题,我的答案只是一个解决方法 – Joseph 2011-03-03 18:12:05