我是backbone.js的新手,也是前端工作的新手,还没有弄清楚生命周期是如何工作的.
我们有一个Django后端,它为我们提供了html模板,我们基本上只用作框架.所有逻辑都在Backbone视图中处理.
我目前遇到的问题是我正在尝试绘制图形但是图形函数没有找到基于id的视图,因为它在渲染函数期间不存在,但我不知道如何通过在以后的阶段实现这一目标.
我已尝试在页面完全加载后在Chrome控制台中手动创建视图并且它可以正常工作:
var main = new MainView();
main.showChart();
Run Code Online (Sandbox Code Playgroud)
风景:
var ChartView = Backbone.View.extend({
title: 'Chart',
initialize: function() {
// This assures that this refers to this exact view in each function
// (except within asynchronous functions such as jquery each)
_.bindAll(this);
// Saving parameters given by parent
this.index = this.options.index;
// Retrieve the template from server
var template = _.template(getTemplate('chart.html'));
// Compile the template with given parameters
var compiledTemplate = template({'title': this.title});
// Set the compiled template to …
Run Code Online (Sandbox Code Playgroud) 我有一张交易数据表,这是对未来的预测。由相同日期、类型、位置和产品标识的相同预测因此被多次读取,因为随着时间的推移和重新发送预测变得更加准确。
我想创建一个查询,该查询将对相同类型和相同位置、产品和日期的交易进行分组,然后从这些组中仅选择具有最新更新时间戳的交易。
该表现在有数十万行,随着时间的推移,数以百万计,所以一个合理有效的解决方案将不胜感激:)
示例表:
date | location_code | product_code | quantity | type | updated_at
------------+------------------+---------------+----------+----------+------------
2013-02-04 | ABC | 123 | -26.421 | TRANSFER | 2013-01-12
2013-02-07 | ABC | 123 | -48.1 | SALE | 2013-01-10
2013-02-06 | BCD | 234 | -58.107 | SALE | 2013-01-11
2013-02-06 | BCD | 234 | -60 | SALE | 2013-01-10
2013-02-04 | ABC | 123 | -6.727 | TRANSFER | 2013-01-10
Run Code Online (Sandbox Code Playgroud)
想要的结果:
date | location_code | product_code | quantity | …
Run Code Online (Sandbox Code Playgroud)