3
我想構建數據網格與排序,搜索和分頁啓用。因此,我使用的是fuelux-datagrid。構建與自定義骨幹網收集fuelux數據網格數據源
MY骨幹看法是這樣的:
var app = app || {};
$(function ($) {
'use strict';
// The Players view
// ---------------
app.PlayersView = Backbone.View.extend({
template: _.template($("#player-template").html()),
initialize: function() {
if(this.collection){
this.collection.fetch();
}
this.listenTo(this.collection, 'all', this.render);
},
render: function() {
this.$el.html(this.template);
var dataSource = new StaticDataSource({
columns: [
{
property: 'playername',
label: 'Name',
sortable: true
},
{
property: 'age',
label: 'A',
sortable: true
}
],
data: this.collection.toJSON(),
delay: 250
});
$('#MyGrid').datagrid({
dataSource: dataSource,
stretchHeight: true
});
}
});
});
球員模板只包含模板中fuelux datagrid給出。我的路由代碼某處實例app.playerview與集合作爲
new app.PlayersView({
collection : new app.PlayersCollection
}));
我的球員集合包含播放器模型的列表如下
[{
"id":1,
"playername":"rahu",
"age":13
},
{
"id":2,
"playername":"sahul",
"age":18
},
{
"id":3,
"playername":"ahul",
"age":19
}]
我的數據源類/函數構造列和數據的方法是datasoruce在datasource constructor
但是,我得到的錯誤「未定義的數據源」。有誰能夠幫助我? 我只是想破解代碼,以便在給定示例中代替從本地data.js構造的數據源,我想構建數據源以便從playercollection獲取數據。
此外,如何添加一個額外的列,以便我們可以把編輯標籤insdie,它應該能夠編輯點擊該編輯特定的行模型。
我一直在圍繞着這些。找出答案會很有幫助。
您是否可以嘗試http://stackoverflow.com/a/15746153/33164中建議的方法 - 您在哪裏? –
@AdamAlexander,我非常感謝你的指導。你的指導我走向了正確的方向。我實際上沒有正確設置數據源數據。我修改了datasource.js然後工作。我將發佈修改後的代碼。 – Lasang
很高興聽到它! –