【问题标题】:how to bind data to a table using knockoutjs in c# webforms如何在 c# webforms 中使用 knockoutjs 将数据绑定到表
【发布时间】:2013-01-26 06:46:15
【问题描述】:

我正在从后端获取数据,现在我想将该数据绑定到 webforms 中的表格

我用这种方式从后端获取数据

[WebMethod]
    [ScriptMethod]    
    private string GetAll()
    {
        SqlConnection con = new SqlConnection(@"Data Source=DEVENV1;Initial Catalog=KnockoutData;Integrated Security=True");       
        SqlCommand cmd = new SqlCommand("select * from sampledb", con);
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader();            
    }

现在在 Webforms 中使用 jquery Ajax iam 获取数据,类似这样...

<script type="text/javascript">
       $(document).ready(function () {
           $('#btnEdit').click(function () {
               var viewModel;
               $.ajax({
                   type: "GET",
                   url: "KnockoutJs.aspx/GetAll",
                   contentType: "application/json",
                   success: function (data) {
                       var result = JSON.parse(data);
                   }
               });
           });
<script>

现在如何通过使用 knockoutJs foreach 将此数据绑定到下表

<table border="1">
<tr>
<th>Student Name</th>
<th>Roll No </th>
</tr>        
</table>

【问题讨论】:

标签: knockout.js knockout-mapping-plugin knockout-2.0


【解决方案1】:

在 viewModel 之前的 javascript 类中添加一个构造函数,并将这个值解析为该构造函数。 检查此链接可能会对您有所帮助: Dynamic table in knockoutjs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 2015-02-26
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多