如何将frm php转换为c#或json? [英] How can I convert frm php to c# or json?

查看:74
本文介绍了如何将frm php转换为c#或json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用浏览器-layout 我的应用程序示例

I am using the browser-layout example for my application

我正在尝试添加 到它的两棵树.

I'm trying to add a two trees to it.

我试图在一个单独的文件中定义twotrees,我的主要文件是layout-browser.js,我需要在其中的选项卡中添加它(和其他树).

I'm trying to 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.

问题是我使用的是.net,示例使用的是php

如何在.net中进行这项工作?

How can I make this work in .net?

这是我的代码:

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')

这是get-nodes.php

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

推荐答案

我建议您将问题分为两部分:

I would recommend you break the problem into two pieces:

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

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)

这将确认您所有的javascript,资源等均正常运行,并且您仅在询问有关如何输出某些数据的.NET问题.

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)然后找到一个.NET示例,该示例可让您从获取数据的任何地方创建JSON或XML(我想可能是数据库).您只需要输出看起来像可以正常工作的静态数据即可.如果您不太了解PHP或.NET,那么学习.NET来使输出正确无误比尝试移植该示例要容易得多.如果您遇到困难,我会重新发布一个不同的问题,并询问如何动态输出由该静态文件产生的数据,并且不涉及extjs复杂性!

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!

希望这会有所帮助.

这篇关于如何将frm php转换为c#或json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆