对yii使用javascript变量
我有一个控制器,它输出一个json,用于用highcharts绘制图形 1-首先,我必须选择一个时间范围,将计时器开始日期和结束日期变量传递给我的控制器,并根据该时间提取数据并生成图形 2-现在a希望使用相同的json输出以表格格式绘制相同的数据 例如,我可以使用highchart代码中使用的开始日期和结束日期来绘制带有datatables的表吗 我的json看起来像这样对yii使用javascript变量,yii,datatable,Yii,Datatable,我有一个控制器,它输出一个json,用于用highcharts绘制图形 1-首先,我必须选择一个时间范围,将计时器开始日期和结束日期变量传递给我的控制器,并根据该时间提取数据并生成图形 2-现在a希望使用相同的json输出以表格格式绘制相同的数据 例如,我可以使用highchart代码中使用的开始日期和结束日期来绘制带有datatables的表吗 我的json看起来像这样 {"name":"sensor_1","data":[["2012-12-01 15:00:00.070",45],["20
{"name":"sensor_1","data":[["2012-12-01 15:00:00.070",45],["2012-12-01 15:00:00.281",95],["2012-12-01 15:00:00.883",104]] ........]},"name":"sensor_2","data":[[]........]}
我用了这个密码
我不知道你在问什么。一些标点符号和换行符可能会澄清这一点。很抱歉,我的问题只是如何使用“开始日期”和“结束日期”从yii控制器中绘制一个表,并将其传递给控制器。因此,您希望在服务器端(例如,在视图中使用PHP)还是在客户端使用javascript呈现这些数据?你尝试过什么?这两种方法对我来说都没问题,我在我的视图中尝试过,但我无法制作一个只从开始和结束获取数据的过滤器,对于客户端,我现在知道了如何做。让我们看看你在视图中尝试过的代码,这样我们可以尝试让它为你工作。
$(document).ready(function(){
var startDateTextBox = $('#startDate'); /// start date passed to yii controller
var endDateTextBox = $('#endDate');
$("#btnSubmit").click(function() {
if(startDateTextBox.val()!="" && endDateTextBox.val()!=""){
$.ajax({
type: "get",
url: "<?php echo
CController::createUrl('ecg/GetSensorsData'); ?>",
data: {"ecgId" : "<?php echo $modelsensors['node_id'] ;?>" ,
"sDate": $('#startDate').val() , "eDate": $('#endDate').val()},
dataType:"json",
success: function(response, status) {
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'spline'
},
},
xAxis: {
type: 'datetime',
},
},
series: response
});
},
error: function (response, status) {
alert("An error occured while loading
data!");
}
});
}
else
{
alert("Choose date range!")
}
});
startDateTextBox.datetimepicker({
//showSecond: true,
dateFormat : 'yy-mm-dd',
timeFormat: 'HH:mm ',
stepHour: 1,
stepMinute: 1,
//stepSecond: 0.5,
onClose: function(dateText, inst) {
if (endDateTextBox.val() != '') {
var testStartDate =
startDateTextBox.datetimepicker('getDate');
var testEndDate = endDateTextBox.datetimepicker('getDate');
if (testStartDate > testEndDate)
endDateTextBox.datetimepicker('setDate',
testStartDate);
}
else {
endDateTextBox.val(dateText);
}
},
onSelect: function (selectedDateTime){
endDateTextBox.datetimepicker('option', 'minDate',
startDateTextBox.datetimepicker('getDate') );
}
});
endDateTextBox.datetimepicker({
showSecond: true,
dateFormat : 'yy-mm-dd',
timeFormat: 'HH:mm:ss',
stepHour: 1,
stepMinute: 1,
stepSecond: 0.5,
onClose: function(dateText, inst) {
if (startDateTextBox.val() != '') {
var testStartDate = startDateTextBox.datetimepicker('getDate');
var testEndDate = endDateTextBox.datetimepicker('getDate');
if (testStartDate > testEndDate)
startDateTextBox.datetimepicker('setDate', testEndDate);
}
else {
startDateTextBox.val(dateText);
}
},
onSelect: function (selectedDateTime){
startDateTextBox.datetimepicker('option', 'maxDate',
endDateTextBox.datetimepicker('getDate') );
}
});
});
</script>
<tbody>
<?php if(count($modelSensors)>=1) {
foreach($modelSensors as $models) : ?>
<tr>
<td> <?php echo $models['information_sensor_id'] ; ?> </td>
<td> <?php echo $models['information_sensor_time'] ; ?> </td>
<td> <?php echo $models['information_sensor_value'] ; ?> </td>
<td> <?php echo $models['sensor_id'] ; ?> </td>
</tr>
<?php endforeach;
}else {?>
<tr>
<td colspan='2' style="text-align:center;">Sorry no data found for this Node</td>
</tr>
<?php } ?>
</tbody>
var_dump($modelSensors);
array
0 =>
object(SensorInfo)[1384]
private '_md' (CActiveRecord) =>
object(CActiveRecordMetaData)[85]
public 'tableSchema' =>
object(CMysqlTableSchema)[98]
...
public 'columns' =>
array
...
public 'relations' =>
array
...
public 'attributeDefaults' =>
array
...
private '_model' =>
object(SensorInfo)[84]
...
private '_new' (CActiveRecord) => boolean false
private '_attributes' (CActiveRecord) =>
array
'information_sensor_id' => string '1' (length=1)
'information_sensor_time' => string '2012-12-01 15:00:00' (length=19)
'information_sensor_value' => string '95' (length=2)
'sensor_id' => string 'sensor1' (length=7)
....................