如何使用Knockout JS和asp.net绑定和保存数据列表 [英] How to bind and save a List of data using Knockout JS and asp.net

查看:52
本文介绍了如何使用Knockout JS和asp.net绑定和保存数据列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我创建了一个显示数据列表的页面。

.chstml文件是

 <   h2  > 客户资料配置<   / h2  >  

< hr < span class =code-keyword> / >
< table class = table table-striped table-bordered table-condensed >
< tr >
< th > 数据字段名称< / th >
< th > 显示文字< / th >
< th > 是强制性的< / th >
< > IsActive &l t; / th >
< th > < ; / th >
< / tr >
< tbody data- bind = foreach:CustomerProfileConfigurations > ;
< tr >
< td class = 名称 > < a data-bind = text:DataFieldName,click:$ parent.editCustomerProfileConfiguration > < / a > < / td >
< td >
< input class = input-large data-bind =' value:DisplayText' 占位符 = DisplayText < span class =code-attribute> / >
< / td >
< td >
< 输入 class = input-large data-bind =' 值:IsMandatory' 占位符 = IsMandatory / >
< / td >
< td >
< span class =code-keyword>< input class = input-large data-bind =' value:IsActive' 占位符 = IsActive / >
< / td >

< / tr >



< / tbody >
< / table >
< 输入 type = button class = btn btn-small btn-primary value = 保存客户资料配置 data-bind = click:$ root.UpdateCustomerProfileConfiguration / >


< script src = 〜/ Scripts / CustomerProfileConfigurationTest.js > < / script >





和Javascript代码是



var CustomerProfileConfigurationViewModel = function(){

debugger;

var self = this;

var url =/ CustomerProfileConfiguration / GetAllCustomerProfileConfigurations;

var refresh = function(){

$ .getJSON(url,{},function(data){

self.CustomerProfileConfigurations(data);

});

};



//公共数据属性

self.CustomerProfileConfigurations = ko.observableArray([]);

//公共运营



self.UpdateCustomerProfileConfiguration = function(){



//我怎么能绑定页面数据并发送更新.............







};



refresh();

};

ko.applyBindings(new CustomerProfileConfigurationViewModel( ));



页面完美地查看数据。

问题是,如何更新数据列表?

如何通过saveCustomerProfileConfiguration javascript方法将java脚本文件中的数据列表单击更新按钮并将其发送到管理器层进行保存?

解决方案

< blockquote> parent.editCustomerProfileConfiguration > ; < / a > < / td >
< td >
< input class = input-large data-bind =' value:DisplayText' 占位符 = DisplayText / >
< / td >
< td >
< 输入 class = input-large data-bind =' value: IsMandatory' 占位符 = IsMandatory / >
< ; / td >
< td >
< 输入 class = input-large data-bind =' value:IsActive' 占位符 = IsActive / >
< / td >

< / tr >



< / tbody >
< / table >
< ; 输入 type < span class =code-keyword> = button class = btn btn-small btn-primary < span class =code-attribute> value = 保存客户配置文件配置 data-bind = click:


root.UpdateCustomerProfileConfiguration / >


< script src = 〜/ Scripts / CustomerProfileConfigurationTest.js > < / script >





和Javascript代码是



var CustomerProfileConfigurationViewModel = function(){

调试器;

var self = this;

var url =/ CustomerProfileConfiguration / GetAllCustomerProfileConfigurations;

var refresh = function(){


.getJSON(url,{},function(data){

self.CustomerProfileConfigurations(data);

});

};



//公共数据属性

self.CustomerProfileConfigurations = ko.observableArray([]);

//公共运营



self.UpdateCustomerProfileConfiguration = function(){



//我怎么能绑定页面数据并发送更新.............







};



refresh();

};

ko。 applyBindings(new CustomerProfileConfigurationViewModel());



页面正在查看数据。

问题是,如何更新列表数据?

如何通过saveCustomerProfileConfiguration javascript方法将java脚本文件中的数据列表单击更新按钮并将其发送到管理器层进行保存?


Hi I have create a page that display a list of data.
.chstml file is

<h2>Customer Profile Configuration </h2>

<hr />
<table class="table table-striped table-bordered table-condensed">
    <tr>
        <th>Data Field Name</th>
        <th>Display Text</th>
        <th>Is Mandatory</th>
        <th>IsActive</th>
        <th></th>
    </tr>
    <tbody data-bind="foreach: CustomerProfileConfigurations">
        <tr>
            <td class="name"><a data-bind="text: DataFieldName, click: $parent.editCustomerProfileConfiguration"></a></td>
             <td>
                <input class="input-large" data-bind='value: DisplayText' placeholder="DisplayText" />
            </td>
             <td>
                <input class="input-large" data-bind='value: IsMandatory' placeholder="IsMandatory" />
            </td>
            <td>
                <input class="input-large" data-bind='value: IsActive' placeholder="IsActive"/>
            </td>

             </tr>



    </tbody>
</table>
 <input type="button" class="btn btn-small btn-primary" value="Save Customer Profile Configuration" data-bind="click:$root.UpdateCustomerProfileConfiguration" />


<script src="~/Scripts/CustomerProfileConfigurationTest.js"></script>



and Javascript Code is

var CustomerProfileConfigurationViewModel = function () {
debugger;
var self = this;
var url = "/CustomerProfileConfiguration/GetAllCustomerProfileConfigurations";
var refresh = function () {
$.getJSON(url, {}, function (data) {
self.CustomerProfileConfigurations(data);
});
};

// Public data properties
self.CustomerProfileConfigurations = ko.observableArray([]);
// Public operations

self.UpdateCustomerProfileConfiguration= function () {

// How can I bind the page data and send for update .............



};

refresh();
};
ko.applyBindings(new CustomerProfileConfigurationViewModel());

Page is working perfectly to view data.
The problem is, How can I update list of data ?
How can i Bind list of data in java script file through saveCustomerProfileConfiguration javascript method by click on Update button and send it to manager layer for save it?

解决方案

parent.editCustomerProfileConfiguration"></a></td> <td> <input class="input-large" data-bind='value: DisplayText' placeholder="DisplayText" /> </td> <td> <input class="input-large" data-bind='value: IsMandatory' placeholder="IsMandatory" /> </td> <td> <input class="input-large" data-bind='value: IsActive' placeholder="IsActive"/> </td> </tr> </tbody> </table> <input type="button" class="btn btn-small btn-primary" value="Save Customer Profile Configuration" data-bind="click:


root.UpdateCustomerProfileConfiguration" /> <script src="~/Scripts/CustomerProfileConfigurationTest.js"></script>



and Javascript Code is

var CustomerProfileConfigurationViewModel = function () {
debugger;
var self = this;
var url = "/CustomerProfileConfiguration/GetAllCustomerProfileConfigurations";
var refresh = function () {


.getJSON(url, {}, function (data) {
self.CustomerProfileConfigurations(data);
});
};

// Public data properties
self.CustomerProfileConfigurations = ko.observableArray([]);
// Public operations

self.UpdateCustomerProfileConfiguration= function () {

// How can I bind the page data and send for update .............



};

refresh();
};
ko.applyBindings(new CustomerProfileConfigurationViewModel());

Page is working perfectly to view data.
The problem is, How can I update list of data ?
How can i Bind list of data in java script file through saveCustomerProfileConfiguration javascript method by click on Update button and send it to manager layer for save it?


这篇关于如何使用Knockout JS和asp.net绑定和保存数据列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆