剑道UI远程修改数据源 [英] Kendo UI Remote DataSource Modification

查看:171
本文介绍了剑道UI远程修改数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据源剑道从远程服务器(JSON)采用其数据和它的数据绑定到客户端剑道模板。

I have a Kendo DataSource that takes its data from a remote server (Json) and it bind the data to a kendo template in the client-side.

在客户端,现在我只是显示数据。不过,我想数据源中添加/删除数据,以及。我怎样才能修改后发回数据源服务器并将其存储在那里?

On the client, right now I just display the Data. However, I want to add/remove data in the dataSource as well. How can I send the dataSource after modification back to server and store it in there ?

下面是什么,我试图做一个很好的例子。虽然这个例子从一个局部变量读取数据,请你让我知道:

Here is a good example of what I am trying to do. While this example reads its data from a local variable, would you please let me know:

我怎么能存储在用户后,服务器端的数据源使客户端上修改?

http://jsfiddle.net/derickbailey/D4g8S/

例如Add方法只更新客户端上的数据源。不过,我想将它发送到服务器和存储它的一些怎么有。作为一个结果,如果别人在另一台客户机打开同一个网页,他/她可以看到的变化也是如此。

For example the add method just update the datasource on the client side. However, I want to send it to the Server and store it some how there. As a results, if someone else open the same web page in another client, he/she can see the changes as well.

$("#add").click(function(e){
     e.preventDefault();

     var $todo = $("input[name='description']");

     currentId += 1;
     dataSource.add({
     id: currentId,
     done: false,
     description: $todo.val()
     });

     $todo.val("");
     $todo.focus();
});

我在服务器端使用C#.NET MVC。

I am using C# .Net MVC on the server side.

推荐答案

据我所知,你是问你能如何使基于对客户端更改服务器的更改?如果这是真的,你可以做三件事情:

As I understand you are asking how you can made server changes based on changes on client side? If is that true you can do three things:


  • 您修改渔获量数据(添加,删除,更新),

  • 序列化到JSON,

  • 发送到控制器的动作。

下面是简单的例子,你可以阅读如何从数据源的数据:

Here is simple example how you can read data from your datasource:

 var dataSource = new kendo.data.DataSource({
  data: [
    { id: 1, name: "Jane Doe", age: 30 },
    { id: 2, name: "John Doe", age: 33 }
  ] 
});

dataSource.fetch(function(){
    // reading data from dataSource
    var raw = dataSource.data();
    // entire dataSource
    alert("This is entire dataSource: " + JSON.stringify(raw)); 
    // this is what will be removed
    alert("This is removed: " + JSON.stringify(raw[0]));    
    dataSource.remove(raw[0]);          
    // this is what is rest
    alert("This is rest: " + JSON.stringify(raw));
});

在分配这些数据的一些对象,你可以序列化为JSON有:JSON.stringify(数据)方法

After you assign these data to some object you can serialize into JSON with: JSON.stringify(data) method.

比你可以发布这些数据到控制器的动作,并做了一些工作。如何发布JSON到MVC控制器是常见的问题,请阅读<一href=\"http://stackoverflow.com/questions/17370062/posting-json-data-via-jquery-to-asp-net-mvc-4-controller-action\">here.

Than you can post these data to controller's action and do some work. How to post JSON to MVC controller is common question, please read here.

有关删除和更新是相似的。基本上,你必须抓住你想要的数据,序列化和后采取行动。

For deleting and updating is similar. Basically you have to catch data which you want, serialize and post to action.

这篇关于剑道UI远程修改数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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