2012-07-18 66 views
3

通过XHR在当前和日期使用复杂的json对象的最佳方式是什么?javascript客户端中的服务器端数据绑定

在做数据绑定,在JavaScript中,到目前为止,我还用煎茶的Ext.Js /煎茶触摸模型

如:

Store = Ext.create('Ext.data.Store',{ 
    Constructor: function (config) { 
     var config = Ext.apply({}, config, { 
      model: 'BasicModel', 
      proxy: { 
       type: 'ajax', 
       url: 'myServerUrl.json', 
       reader: { 
        type: 'json' 
       } 
      } 
     }); 
    } 
});  

,让我消耗服务器的数据很容易,也为商店周围的各种酷魔术提供了便利的方法(REST /排序等)。

目前,我正在尝试在一些项目中使用较少的ExtJs,因为在某些方面它有点沉重,因此我们正在寻找与Ext的数据存储具有相似/更好功能的东西,而不是ExtJS (例如非Ext核心)

目前最好的XHR实用工具包是什么?

回答

1

我会推荐Knockout.JS或Backbone。

从Knockout.js documentation

HTML

<p>First name: <input data-bind="value: firstName" /></p> 
<p>Last name: <input data-bind="value: lastName" /></p> 
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2> 

JS

// Here's my data model 
var ViewModel = function(first, last) { 
    this.firstName = ko.observable(first); 
    this.lastName = ko.observable(last); 

    this.fullName = ko.computed(function() { 
     // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName. 
     return this.firstName() + " " + this.lastName(); 
    }, this); 
}; 

ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work 

正如我所说,骨干也是一个解决方案,你spesific题。 Here是由noobs的noob设计的Backbone教程。 Here是关于跨域处理的更中级教程