【问题标题】:Iterate table and set values in a List type object迭代表并在 List 类型对象中设置值
【发布时间】:2013-06-17 03:12:13
【问题描述】:

我在Company 类中有一个List<BankAccount> Company_Accounts 属性。 在CreateCompany 页面上,一个或多个BankAccount 信息正在动态输入到表格中。我希望 javascript/jquery 代码迭代每一行并创建一个新的Account 类型对象和Company_Accounts 中的这个推送对象。

【问题讨论】:

    标签: c# jquery html knockout.js


    【解决方案1】:
    // create your empty array, or get a previous array
    $(#tableid tr).each(function(index, element) {
      // we are itering through every row of the table. Index is the number of the line (from 0), and element the line
      // here some treatment to read the columns and create a new AccountType
      // Check if same object already exist in table (maybe), if not push it back to the array
    });
    

    在不知道对象原型的情况下无法为您提供更多帮助,如果您想在每次修改表时刷新数组。

    【讨论】:

      【解决方案2】:
      class Company{ 
                     string Name{get; set;} 
                     string address{get;set;} 
                     IList<BankAccount> Accounts{get; set;}
                   } 
      
      class BankAccount{
                         Company CompanyName{get; set;} 
                         string BankName{get; set;} 
                         string AccountNo{get; set;} 
                         string BankAddress{get; set;}
                       } 
      On create page for company i create and delete dynamically new BankAccount information by taking entry in Table's <td> cell having inputbox.
      I have to bind the List of newly created BankAccount to the CompanyModel on view page
      

      【讨论】:

        猜你喜欢
        • 2016-05-07
        • 1970-01-01
        • 2015-11-28
        • 2018-12-06
        • 2011-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-22
        相关资源
        最近更新 更多