要完成目录树的构建,需要前台ExtJS构筑页面,后台处理逻辑,中间由JSON传递数据。

  首先搭建后台环境:

 require "httpd"
require "lfs" request, args = ... local s = {root = {
text = "rootNode",
expanded = true,
children = {
{
text = 'book1',
leaf = true
},
{
text = "book2",
expanded = true,
children = {
{
text = "con1",
leaf = true
},{
text = "con2",
leaf = true
}
}
},
{
text = "book3",
expanded = true,
leaf = true
}
}
}
} local cjson = require("cjson")
local tJson = cjson.encode(s) httpd.set_content_type("text/json")
httpd.write(tJson)

  这里虚拟了一个树数据结构s,将其打包后返回给请求方。

  然后是html部分:

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ExtJS TreePanel</title>
<link rel="stylesheet" type="text/css" href="../../ext-5.0.0/examples/shared/example.css" /> <script type="text/javascript" src="../ext-5.0.0/examples/shared/include-ext.js"></script>
<script type="text/javascript" src="../ext-5.0.0/examples/shared/options-toolbar.js"></script> <script type="text/javascript" src="test.js" charset="utf-8" ></script> </head>
<body style=" margin: 0; padding: 0;">
</body>
</html>

  最后是ExtJS部分:

 Ext.require('Ext.tree.Panel')

 Ext.onReady(function(){
Ext.Ajax.request({
url: 'm.lua',     //后台文件path
method: 'post',
params: {
action: 'getDir',
},
success: function(response){
var text = response.responseText;
var obj = eval('(' + text + ')');
console.log(obj);
},
failure: function() {
Ext.Msg.alert("失败","失败了");
}
});
});

  其中response内容是这样的:

  所以可以用"response.responseText"来调用响应内容的主体。

  在数据传输流程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键。

  JSON字符串转换为JSON对象:

    var obj = eval('(' + str + ')');

  这样就能获取一个可供使用的JSON对象了。

    

【Lua】LWT后台用JSON与 ExtJS传递数据的更多相关文章

  1. ASP.NET MVC中从后台控制器(Controller)传递数据到前台页面视图(View)方式

    方式一: 数据存储模型Model: public class CalendarEvent { public string id { get; set; } public DateTime start ...

  2. EF5+MVC4系列(7) 后台SelectListItem传值给前台显示Select下拉框;后台Action接收浏览器传值的4种方式; 后台Action向前台View视图传递数据的四种方式(ViewDate,TempDate,ViewBag,Model (实际是ViewDate.Model传值))

    一:后台使用SelectListItem 传值给前台显示Select下拉框 我们先来看数据库的订单表,里面有3条订单,他们的用户id对应了 UserInfo用户表的数据,现在我们要做的是添加一个Ord ...

  3. HTTP传递数据的几种方法

    Http请求的时候,需要传递参数给后端,一般都是key-value的形式,传递的方法有很多种 例如需要传递的数据是 dict(key1=value1,key2=value2) 1. URL参数 把参数 ...

  4. 【Lua】Lua + LWT + ExtJS构建目录树

    Lua处理后台逻辑,Lua lwt搭建后台程序,ExtJS根据后台传来的json数据构建目录树. 前台html和ExtJS代码不用多讲,直接上代码: treePanel.html <html&g ...

  5. 前台传递给后台的JSON字符串中的引号 “” 在JAVA后台被转义为 "

    前台传递给后台的JSON字符串中的引号 "" 在JAVA后台被转义为 &quot 1.问题: 前台数据,JSON字符串带有引号 "" ,数据被传递到后台 ...

  6. 传递给后台的Json数据解析

    后台代码如下: public void ProcessRequest(HttpContext context) { context.Response.ContentType = "appli ...

  7. .net后台获取DataTable数据,转换成json数组后传递到前台,通过jquery去操作json数据

    一,后台获取json数据 protected void Page_Load(object sender, EventArgs e){  DataTable dt = DBhepler.GetDataT ...

  8. Struts2中的JSON问题——后台返回JSON字符串到前台

    最近做一个项目遇到一个比较棘手的问题,项目后台采用struts2+Hibernate3+Spring3,前台采用ExtJs4.笔者目前仍是一名大二学生吗,后台框架完全是毫无任何基础,从零学,现学现用. ...

  9. Asp.net MVC 传递数据 从前台到后台,包括单个对象,多个对象,集合

    今天为大家分享下 Asp.net MVC 将数据从前台传递到后台的几种方式. 环境:VS2013,MVC5.0框架 1.基本数据类型 我们常见有传递 int, string, bool, double ...

随机推荐

  1. 桂林理工大学第十届java程序设计初试竞赛试题

    原创 三.程序设计题(不得改变已经给出的部分,允许添加新的辅助函数或类)(共36分) (6分)1.以下函数的功能是判断一个正整数是否为质数,若是返回true,否则返回false.其中参数data为要判 ...

  2. [LeetCode 题解]: Validate Binary Search Tree

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  3. repo搭建

    [root@op-yum01]# cat /home/work/yumdata/rsync-reposync.sh #!/bin/bash #Purpose: Sync centos7 repos v ...

  4. “全栈2019”Java第六十一章:如何实现接口?

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  5. LoadRunner12_脚本中运行JavaScript

    版权声明:本文为博主原创文章,未经博主允许不得转载. [系统及软件配置] LR版本:12.53 JDK版本:1.8 函数:web_js_run,该函数仅在LR12版本提供支持,LR11不支持JavaS ...

  6. js 自定义获得类class和获得id

    使用js获取类名,但是低版本浏览器不支持getElementsByClassName,所以我们就需要自定义getClassName,方便跨浏览器使用. 当然,如果采用jquery就不需要. //获取类 ...

  7. day0202 (%s)

    #格式化输出# % s d# name = input('请输入姓名')# age = input('请输入年龄')# height = input('请输入身高')# msg = "我叫% ...

  8. JavaWeb学习笔记(十五)—— 使用JDBC进行批处理

    一.什么是批处理 批处理就是一批一批的处理,而不是一个一个的处理! 当你有10条SQL语句要执行时,一次向服务器发送一条SQL语句,这么做效率上很差!处理的方案是使用批处理,即一次向服务器发送多条SQ ...

  9. Vue.js路由跳转带参数到模板组件。

    从SalesOrderQuery组件跳到SalesOrder组件,并且通过params属性携带数据. handleClick(row) { //alert(row.FSaleName);//获取该行F ...

  10. archlinux安装tftp

    1. 安装  [guo@archlinux ~]$ sudo pacman -S tftp-hpa 2. 启用  [guo@archlinux ~]$ systemctl start tftpd.se ...