2012-07-18 100 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是關於跨域處理的更中級教程