我的页面上有一个带有数据集合的 Backgrid 视图。Backgrid 视图上方是另一个称为“过滤器”的视图,它允许用户更改数据的日期范围,以便他们可以看到两个日期之间的结果。
我不确定刷新 Backgrid 视图内容的最干净的方法是什么。这是我的代码:
// Fetch data
var fetchingOrders = CRM.request("orders:entities");
// Create layout
var ordersLayout = new List.OrdersLayout();
$.when(fetchingOrders).done(function (orders) {
var ClickableRow = Backgrid.Row.extend({
events: {
"click" : "rowClicked"
},
rowClicked: function () {
CRM.trigger("order:show", this.model.get("RecordID"));
}
});
var customersListView = new Backgrid.Grid({
row: ClickableRow,
columns: CRM.settings.columns.orders,
collection: orders,
className: "simple-table backgrid"
});
var filters = new List.Filters({});
filters.on("orders:filter", function (startdate, enddate) {
});
ordersLayout.on("show", function () {
ordersLayout.filters.show(filters);
ordersLayout.backgrid.show(customersListView);
});
CRM.mainRegion.show(ordersLayout);
});
该CRM.request("orders:entities")
行使用此功能:
getOrders: function (startdate, enddate) {
var orders = new Entities.Orders();
var defer = $.Deferred();
orders.fetch({
data: {
action: "search",
dateRangeColumn: "RecordDate",
startDate: startdate || "2013-11-06",
endDate: enddate || "2013-11-06",
// startDate: startdate || Utilities.currentDate,
// endDate: enddate || Utilities.currentDate
},
success: function (data) {
defer.resolve(data);
},
error: function (collection, response, options) {
console.log(response);
console.log("Error loading Orders…");
}
});
return defer.promise();
},
你可能已经注意到了这个filters.on("orders:filter", function (startdate, enddate) {
块。每当用户更改视图中的开始或结束日期时,我都会触发此操作filters
,但我不确定从这里开始做什么,因为我基本上需要重新运行上述所有代码作为设置。
建议?谢谢!