2011-03-02 69 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