2015-05-13 36 views
-1

這是我的表,我使用JSON獲取數據列表,並填充此表,隱藏「無表可用數據」

<table id="tblClaimSearch" class="display responsive nowrap" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th><input type="checkbox" id="ChkboxClaimHeader" name="ChkboxClaimHeader" value="false"></th> 
      <th>Claim #</th> 
      <th>Client Name</th> 
      <th>Amount</th> 
      <th>Deduction</th> 
      <th>Type</th> 
      <th>Status</th> 
     </tr> 
    </thead> 
    <tbody>      

    </tbody> 
</table> 

我的jQuery擁有JSON結果,我得到的結果和追加行根據我的數據表身,

$(document).ready(function() { 
$.ajax({ 
      url: '@Url.Action("ClaimResultTest", "Claims")', 
      data: { seacrhClaimNumber: claimNumberToBeSearched }, 
      type: 'POST', 
      success: function (data) { 
        var dataClaims = data.Claims;//This has the complete list 
        for (i = 0; i < dataClaims.length; i++) { 
        alert(dataClaims[i].ClaimNumber); 
        $("#tblClaimSearch").find('tbody') 
          .append($('<tr>') 
          .append($('<td><input type="checkbox">')) 
          .append($('<td>').text(dataClaims[i].ClaimNumber)) 
          .append($('<td>').text(dataClaims[i].Client)) 
          .append($('<td>').text(dataClaims[i].Amount)) 
          .append($('<td>').text(dataClaims[i].Deduction)) 
          .append($('<td>').text(dataClaims[i].Type)) 
          .append($('<td>').text(dataClaims[i].Status)) 
           ) 
        } 
        } 
       }); 
     }); 

問題是,當沒有數據,我有一排顯示「無表可用的數據」。而即使有數據附加我還是第一排爲「表中沒有可用數據」..當添加了帶有數據的新行時,如何隱藏此消息行?其次,甚至雖然我有16個條目仍顯示「顯示鄰項0」?我在做什麼錯?..

回答

2

您可以使用正則表達式

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Text.RegularExpressions; 


namespace ConsoleApplication28 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string input = "Search Name=\"search1\" BasicString=\"\" SearchText=\"\" SearchNames=\"\" SearchFields=\"\" SearchAnnotations=\"\" SearchCustom=\"\"t"; 
      string pattern = "Name=\"(?'name'[^\"]+)"; 
      string value = Regex.Match(input, pattern).Groups["name"].Value; 
     } 
    } 
} 
0

我會使用正則表達式這一點。這裏有一個小的功能會找到名稱後的值=

public static string NameValueFromString(string input) 
    { 
     string returnValue = null; 

     if (!String.IsNullOrWhiteSpace(input)) 
     { 
      Regex nameValueExpression = new Regex(@"name=""[^""]*""", RegexOptions.IgnoreCase); 
      Match match = nameValueExpression.Match(input); 
      if (match.Success) 
      { 
       Regex valueExpression = new Regex(@"""[^""]*"""); 
       returnValue = valueExpression.Match(match.Value).Value.Trim('"'); 
      } 
     } 

     return returnValue; 
    } 

第一個正則表達式應該找到字符串Name="Something"。 如果確實匹配,則成功。第二個Regex發現"Something"然後修剪報價。