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

发布于 2024-12-02 14:24:53 字数 950 浏览 0 评论 0原文

我使用 extjs 网格视图创建 cakephp 。

为此,我创建了

1)一个我在其中编写的movie_controller控制器文件

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

    }

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

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

3)然后在js文件中我调用这个index.ctp文件

而不是在网格中获取数据。 在 Firebug 中调试时,它显示此数组

{"rows":[{"Movie":{"id":"1","date_":"1970-01-01","notes":"Note13455-"," asset_id":"1","maint_picture":"","maint_condition1":"差","maint_condition2":"新","maint_condition3":"优秀","maint_condition4":"好"}},{"Movie":{"id":"2","date_":"2009-03-20","notes" :"注释2","asset_id":"1"," maint_picture":null,"maint_condition1":"优秀","maint_condition2":"优秀","maint_condition3":"新","maint_condition4":"差"}}]}

==>在此 json 文件中,我如何删除在开始所有记录中显示的电影数组。

I create cakephp with extjs grid view .

For that i create,

1)one movie_controller controller file in which i write

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

    }

2)second create index.ctp file in view/movies/index.ctp

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

3)then in js file i call this index.ctp file

not getting data in grid.
when debugging in firebug it's display this array

{"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"}}]}

==>In this json file how can i remove Movie array which is display in start all record.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

前事休说 2024-12-09 14:24:53
<?php echo  '{"rows":'.$javascript->Object($movies['Movie']).'}'; ?>
<?php echo  '{"rows":'.$javascript->Object($movies['Movie']).'}'; ?>
感性 2024-12-09 14:24:53

如果想从数组中删除第一个数组,我们必须在网格中逐个打印数组。
完成了。

<?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;
 ?>  

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;
 ?>  
蓦然回首 2024-12-09 14:24:53

你越来越近了。尝试使用控制器中的 $movies 变量完成所有工作(记住 MVC 模式!不要破坏它!)。

您可以通过执行类似...

// 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;
    }
}

然后将其转换为 json 对象来实现。

基本上我认为它没有加载数据,因为你的 json 看起来像这样

{"rows":[{"Movie":{"id":"1","date_":"1970-01-01","notes": "Note13455-","asset_id":"1","maint_picture":"","maint_condition1":"差","maint_condition2":"新","maint_condition3":"优秀","maint_condition4":"好"}},{"Movie":{"id":"2","date_":"2009-03-20","notes" :"注释2","asset_id":"1"," maint_picture":null,"maint_condition1":"优秀","maint_condition2":"优秀","maint_condition3":"新","maint_condition4":"差"}}]}

它应该看起来像这样

{
“行”:[{
“id”:“1”,
"date_":"1970-01-01",
"notes":"Note13455-",
"asset_id":"1",
“维护图片”:“”,
"maint_condition1":"差",
"maint_condition2":"新",
"maint_condition3":"优秀",
"maint_condition4":"好"
}, {
“id”:“2”,
"date_":"2009-03-20",
"notes":"注释2",
"asset_id":"1",
“维护图片”:空,
"maint_condition1":"优秀",
"maint_condition2":"优秀",
"maint_condition3":"新",
"maint_condition4":"差"
}
]}

您想要删除 "Movies": {..object..} 部分,因此它只是一个对象数组,例如 {id: 1},{id: 2}, {id: 3} 等。

确保您在 JsonReader 中将行设置为根!

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

You're getting closer. Try doing all the work with your $movies variable in the controller (remember the MVC pattern! Don't break it!).

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.

Basically I think it's not loading the data because your json looks like this

{"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"}}]}

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"
}
]}

You want to remove the "Movies": {..object..} part, so it's just an array of objects like {id: 1},{id: 2},{id: 3} etc.

Make sure you have rows set as your root in your JsonReader!!

var reader = new Ext.data.JsonReader({
    root: 'rows'
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文