简体   繁体   English

通过网格中的显示数据与Ext js的Cake php问题

[英]Cake php with Ext js through display data in grid Problem

I create cakephp with extjs grid view . 我用extjs网格视图创建cakephp。

For that i create, 为此,我创造了

1)one movie_controller controller file in which i write 1)我在其中写入一个movie_controller控制器文件

function index() {
        $this->recursive = 0;                                      
        $this->set('movies', $this->Movie->find("all"));

    }

2)second create index.ctp file in view/movies/index.ctp 2)在view / movies / index.ctp中第二个创建index.ctp文件

 <?php echo  '{"rows":'.$javascript->Object($movies).'}'; ?>

3)then in js file i call this index.ctp file 3)然后在js文件中,我将此索引称为.ctp文件

not getting data in grid. 没有在网格中获取数据。 when debugging in firebug it's display this array 在Firebug中调试时,将显示此数组

{"rows":[{"Movie":{"id":"1","date_":"1970-01-01","notes":"Note13455-","asset_id":"1","maint_picture":"","maint_condition1":"Poor","maint_condition2":" New","maint_condition3":"Excellent","maint_condition4":"Good"}},{"Movie":{"id":"2","date_":"2009-03-20","notes":"Note2","asset_id":"1","maint_picture":null,"maint_condition1":"Excellent","maint_condition2":"Excellent","maint_condition3":"New","maint_condition4":"Poor"}}]} {“ rows”:[{“ Movie”:{“ id”:“ 1”,“ date _”:“ 1970-01-01”,“ notes”:“ Note13455-”,“ asset_id”:“ 1”,“ maint_picture“:”“,” maint_condition1“:”差“,” maint_condition2“:”新建“,” maint_condition3“:”优秀“,” maint_condition4“:” Good“}},{” Movie“:{” id“: “ 2”,“ date _”:“ 2009-03-20”,“ notes”:“ Note2”,“ asset_id”:“ 1”,“ maint_picture”:null,“ maint_condition1”:“ Excellent”,“ maint_condition2”: “ Excellent”,“ maint_condition3”:“新”,“ maint_condition4”:“差”}}]}

==>In this json file how can i remove Movie array which is display in start all record. ==>在此json文件中,如何删除开始所有记录中显示的Movie数组。

<?php echo  '{"rows":'.$javascript->Object($movies['Movie']).'}'; ?>

if want to remove first array remove from array we have to one by one array print in grid. 如果要删除第一个数组,请从网格中逐个打印数组。 its done. 完成。

<?php
$output='{"rows":[';
$total=$ta=count($movies);
for($i=0;$i<$total;$i++)
{
$t=$i+1;
  if($t==$total)
  {
    $output.=$javascript->Object($movies[$i]['Movie']);
  }
  else
  {
    $output.=$javascript->Object($movies[$i]['Movie']).',';
  }
}
$output.=']}';

echo $output;
 ?>  

You're getting closer. 你越来越近了。 Try doing all the work with your $movies variable in the controller (remember the MVC pattern! Don't break it!). 尝试使用$movies变量在控制器中完成所有工作(请记住MVC模式!不要破坏它!)。

You can do so by doing something like... 您可以通过执行以下操作来做到这一点...

// in your controller
$data = null;
$movies = $this->Movie->find('all');

foreach ($movies as $key => $value) {
    foreach ($value['Movie'] as $k => $v {
        $data['rows'][$key][$k] = $v;
    }
}

Then turn that into a json object. 然后将其变成一个json对象。

Basically I think it's not loading the data because your json looks like this 基本上我认为它没有加载数据,因为您的json看起来像这样

{"rows":[{"Movie":{"id":"1","date_":"1970-01-01","notes":"Note13455-","asset_id":"1","maint_picture":"","maint_condition1":"Poor","maint_condition2":" New","maint_condition3":"Excellent","maint_condition4":"Good"}},{"Movie":{"id":"2","date_":"2009-03-20","notes":"Note2","asset_id":"1","maint_picture":null,"maint_condition1":"Excellent","maint_condition2":"Excellent","maint_condition3":"New","maint_condition4":"Poor"}}]} {“ rows”:[{“ Movie”:{“ id”:“ 1”,“ date _”:“ 1970-01-01”,“ notes”:“ Note13455-”,“ asset_id”:“ 1”,“ maint_picture“:”“,” maint_condition1“:”差“,” maint_condition2“:”新建“,” maint_condition3“:”优秀“,” maint_condition4“:” Good“}},{” Movie“:{” id“: “ 2”,“ date _”:“ 2009-03-20”,“ notes”:“ Note2”,“ asset_id”:“ 1”,“ maint_picture”:null,“ maint_condition1”:“ Excellent”,“ maint_condition2”: “ Excellent”,“ maint_condition3”:“新”,“ maint_condition4”:“差”}}]}

it should look like this 它应该看起来像这样

{ "rows": [{ "id":"1", "date_":"1970-01-01", "notes":"Note13455-", "asset_id":"1", "maint_picture":"", "maint_condition1":"Poor", "maint_condition2":" New", "maint_condition3":"Excellent", "maint_condition4":"Good" }, { "id":"2", "date_":"2009-03-20", "notes":"Note2", "asset_id":"1", "maint_picture":null, "maint_condition1":"Excellent", "maint_condition2":"Excellent", "maint_condition3":"New", "maint_condition4":"Poor" } ]} {“ rows”:[{“ id”:“ 1”,“ date _”:“ 1970-01-01”,“ notes”:“ Note13455-”,“ asset_id”:“ 1”,“ maint_picture”:“” ,“ maint_condition1”:“差”,“ maint_condition2”:“新建”,“ maint_condition3”:“优秀”,“ maint_condition4”:“良好”},{“ id”:“ 2”,“ date _”:“ 2009- 03-20”,“ notes”:“ Note2”,“ asset_id”:“ 1”,“ maint_picture”:null,“ maint_condition1”:“ Excellent”,“ maint_condition2”:“ Excellent”,“ maint_condition3”:“ New” ,“ maint_condition4”:“差”}]}

You want to remove the "Movies": {..object..} part, so it's just an array of objects like {id: 1},{id: 2},{id: 3} etc. 您要删除"Movies": {..object..}部分,因此它只是诸如{id: 1},{id: 2},{id: 3}等对象的数组。

Make sure you have rows set as your root in your JsonReader!! 确保在JsonReader中将行设置为根目录!

var reader = new Ext.data.JsonReader({
    root: 'rows'
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM