3
我想使用Fuel UX數據網格來顯示我從數據庫中檢索的一些數據。該頁面來自Ruby on Rails服務器。如何向Rails中的Fuel UX datagrid提供數據?
建立數據對象的JavaScript代碼示例:
var dataSource = new StaticDataSource({
columns: [{
property: 'toponymName',
label: 'Name',
sortable: true
}, {
property: 'countrycode',
label: 'Country',
sortable: true
}, {
property: 'population',
label: 'Population',
sortable: true
}, {
property: 'fcodeName',
label: 'Type',
sortable: true
}],
data: sampleData.geonames,
delay: 250
});
$('#MyGrid').datagrid({
dataSource: dataSource,
stretchHeight: true
});
$('#datagrid-reload').on('click', function() {
$('#MyGrid').datagrid('reload');
});
如果我理解代碼,我要被界定我的專欄,並在列的一些屬性的數據源變量的內部對象,並數據對象正在由sampleData.geonames加載。
的sampleData在爲here
我能做些什麼使用Rails的慣例更換sampleData.geonames?我試着調整這幾種方法來加載rails對象到這裏。
例如,我修改了我的列的屬性字段以對應於我的用戶模型的一些屬性。我試着更換
data: sampleData.geonames,
到
data: <%= @users.to_json %>,
我有點禁區寶石和版本,目前使用Rails 2.3。
感謝您的任何幫助。
你能提供的示例myData中的'...'應該看起來像什麼? – 2013-03-26 02:57:31
當然,它應該是一個對象數組。例如:https://github.com/ExactTarget/fuelux/blob/master/sample/data.js#L9-L1907 – 2013-03-26 11:13:12
與數據網格上的列和數據選項關聯,如下所示:https://github.com /ExactTarget/fuelux/blob/master/index.html#L114-L136 – 2013-03-26 11:14:14