我如何从PHP转换为c#或json(extjs)

i am using the browser-layout example for my application

im trying to add a two trees to it

what im trying to do here is define the twotrees in a separate file, my main file is the layout-browser.js and i need to add this (and others) in the tabs i have in it . feel free to ask me other questions if its not clair and please bare with me im really new to all this and cant get hold of it

the problem is that im using .net and the example is using php

so how can i make this work in .net

here is my code:

Ext.require(['*']);

var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'get-nodes.php'
    },
    root: {
        text: 'Ext JS',
        id: 'src',
        expanded: true
    },
    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
    }]
});

var tree = Ext.create('Ext.tree.Panel', {
    id: 'tree',
    store: store,
    width: 250,
    height: 300,
    columnWidth: 0.5,
    viewConfig: {
        plugins: {
            ptype: 'treeviewdragdrop',
            appendOnly: true
        }
    }
   // ,renderTo: document.body
});

var store2 = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'get-nodes.php'
    },
    root: {
        text: 'Custom Ext JS',
        id: 'src',
        expanded: true,
        children: []
    },
    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
    }]
});

var tree2 = Ext.create('Ext.tree.Panel', {
    id: 'tree2',
    width: 250,
    height: 300,
    columnWidth: 0.5,
    store: store2,
    viewConfig: {
        plugins: {
            ptype: 'treeviewdragdrop',
            appendOnly: true
        }
    }
   // ,renderTo: document.body
});


Ext.define("Ext.app.myTwoTrees",{
extend:"Ext.panel.Panel",

width : 600,
height: 350,
layout: 'column',
items: [
         tree , tree2
       ]

});

i call it in my tab like this

 Ext.create('Ext.app.myTwotrees')

here is the get-nodes.php

<?php
// from php manual page
function formatBytes($val, $digits = 3, $mode = 'SI', $bB = 'B'){ //$mode == 'SI'|'IEC', $bB == 'b'|'B'
   $si = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');
   $iec = array('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi');
   switch(strtoupper($mode)) {
       case 'SI' : $factor = 1000; $symbols = $si; break;
       case 'IEC' : $factor = 1024; $symbols = $iec; break;
       default : $factor = 1000; $symbols = $si; break;
   }
   switch($bB) {
      case 'b' : $val *= 8; break;
      default : $bB = 'B'; break;
   }
  for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
       $val /= $factor;
  $p = strpos($val, '.');
   if($p !== false && $p > $digits) $val = round($val);
   elseif($p !== false) $val = round($val, $digits-$p);
   return round($val, $digits) . ' ' . $symbols[$i] . $bB;
}

// grab the custom params
$path = isset($_REQUEST['path'])&&$_REQUEST['path'] == 'extjs' ? '../../../' : '../../';

$node = isset($_REQUEST['node']) ? $_REQUEST['node'] : '';
   $isXml = isset($_REQUEST['isXml']);

if(strpos($node, '..') !== false){
   die('Nice try buddy.');
}

$nodes = array();
$directory = $path.$node;
   if (is_dir($directory)){
       $d = dir($directory);
        while($f = $d->read()){
            if($f == '.' || $f == '..' || substr($f, 0, 1) == '.') continue;

    $filename = $directory . '/' . $f;
    date_default_timezone_set('America/Los_Angeles');
    $lastmod = date('M j, Y, g:i a', filemtime($filename));

    if(is_dir($directory.'/'.$f)){
        $qtip = 'Type: Folder<br />Last Modified: '.$lastmod;
        $nodes[] = array(
            'text' => $f,
            'id'   => $node.'/'.$f,
            'cls'  => 'folder'
        );
    } else {
        $size = formatBytes(filesize($filename), 2);
        $qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;
        $nodes[] = array(
            'text' => $f,
            'id'   => $node.'/'.$f,
            'leaf' => true,
            'cls'  => 'file'
        );
    }
}
$d->close();
}

if ($isXml) {
    $xmlDoc = new DOMDocument();
    $root = $xmlDoc->appendChild($xmlDoc->createElement("nodes"));
    foreach ($nodes as $node) {
    $xmlNode = $root->appendChild($xmlDoc->createElement("node"));
    $xmlNode->appendChild($xmlDoc->createElement("text", $node['text']));
    $xmlNode->appendChild($xmlDoc->createElement("id", $node['id']));
    $xmlNode->appendChild($xmlDoc->createElement("cls", $node['cls']));
    $xmlNode->appendChild($xmlDoc->createElement("leaf", isset($node['leaf'])));
}
header("Content-Type: text/xml");
$xmlDoc->formatOutput = true;
echo $xmlDoc->saveXml();
} else {
    echo json_encode($nodes);
}

thanks a lot

dougang6821
dougang6821 这不是“帮我写我的代码”网站,而是一个“帮我解决这个问题”的网站。如果你不知道如何编码,你应该先看一些教程。买一些书......开始吧。
9 年多之前 回复
dongyao1915
dongyao1915 甚至不知道如何开始,我几乎没有启动.net,并且无法真正理解这个PHP代码。即时通讯要求一种方法来做它或绕过它仍然得到相同的结果,我不关心数据或任何东西,只需要在树之间拖放工作
9 年多之前 回复
douren9077
douren9077 这个问题很多。你应该做的是尝试自己转换它,然后回到这里,提出有关转换过程中遇到的问题的具体问题。
9 年多之前 回复

2个回答



我建议你将问题分成两部分:</ p>

1)更改 url:'get-nodes.php'</ code>到 url:'my-dotnet-url </ code>并使.NET页面返回静态JSON或XML(将值硬编码到树中)</ p>

这将确认您的所有javascript,资源等工作正常,并且您只询问有关如何输出某些数据的.NET问题。</ p>

2)然后找一个.NET示例,它允许您从获取数据的任何地方创建JSON或XML(我猜可能是数据库)。 您只需要输出看起来像正常工作的静态数据。 如果您不太了解PHP或.NET学习.NET以获得正确的输出将比尝试移植该示例更容易。 如果你遇到困难,我会重新发布一个不同的问题,并询问如何动态输出静态文件产生的数据,并且不涉及extjs并发症!</ p>

希望这有助于 。</ p>
</ div>

展开原文

原文

I would recommend you break the problem into two pieces:

1) change url: 'get-nodes.php' to url: 'my-dotnet-url and make the .NET page return static JSON or XML (hardcode the values to the tree)

That will confirm all your javascript, resources, etc. is working properly and that you are only asking a .NET question about how to output certain data.

2) Then find a .NET example that will let you create JSON or XML from wherever you are getting data (I'm guessing probably a database). You just need the output to look like your static data that worked correctly. If you don't know much PHP or .NET learning .NET to get your output correct would be easier than trying to port over that example. If you get stuck, I'd repost a different question and ask how to output the data that results from that static file dynamically and don't have the extjs complication involved!

Hope this helps.

展开原文

原文

Try Dextop. It's an application framework for connection between ASP.NET and Ext JS.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐