当前位置: 首页 > news >正文

根据条件获取json(无限级)中指定的对象

JSON:

 

ExpandedBlockStart.gif 代码
[
    {
" id " : " 1 " , " text " : " 电脑整机 " , " parentid " : " 0 " , " children " :[
        {
" id " : " 2 " , " text " : " 笔记本 " , " parentid " : " 1 " , " children " :[
            {
" id " : " 31 " , " text " : " SONY " , " parentid " : " 2 " , " children " :[]},
            {
" id " : " 23 " , " text " : " LENOVO " , " parentid " : " 2 " , " children " :[]},
            {
" id " : " 25 " , " text " : " IBM " , " parentid " : " 2 " , " children " :[]},
            {
" id " : " 26 " , " text " : " 宏基 " , " parentid " : " 2 " , " children " :[]},
            {
" id " : " 27 " , " text " : " 联想 " , " parentid " : " 2 " , " children " :[]},
            {
" id " : " 28 " , " text " : " 联想2 " , " parentid " : " 2 " , " children " :[]}
        ]},
        {
" id " : " 3 " , " text " : " 上网本 " , " parentid " : " 1 " , " children " :[]},
        {
" id " : " 4 " , " text " : " 平板电脑 " , " parentid " : " 1 " , " children " :[]},
        {
" id " : " 5 " , " text " : " 台式机 " , " parentid " : " 1 " , " children " :[]},
        {
" id " : " 6 " , " text " : " 服务器 " , " parentid " : " 1 " , " children " :[]}
    ]},
    {
" id " : " 7 " , " text " : " 电脑配件 " , " parentid " : " 0 " , " children " :[
        {
" id " : " 8 " , " text " : " CPU " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 9 " , " text " : " 主板 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 10 " , " text " : " 显卡 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 11 " , " text " : " 硬盘 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 12 " , " text " : " 内存 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 13 " , " text " : " 机箱 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 14 " , " text " : " 电源 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 15 " , " text " : " 显示器 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 16 " , " text " : " 刻录机/光驱 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 17 " , " text " : " 声卡 " , " parentid " : " 7 " , " children " :[]},
        {
" id " : " 18 " , " text " : " 扩展卡 " , " parentid " : " 7 " , " children " :[]}
    ]}
]

 

 

js:

 

ExpandedBlockStart.gif 代码
var obj;
function  searchtree(nodes,id) {
    
    $.each(nodes,  function  (i, n) {
        
if  (n.id  ==  id) {
            obj 
=  n;
            
return   false ;
        }
        
else  {
            
if  (n.children.length  >   0 ) {
                
searchtree(n.children, id);
            
}
        }
    });

    
return  obj;
}

 

 

 

 

相关文章:

  • ASP.NET中JavaScript 调用后台事件和方法
  • WF4.0中如何将C#流程装换成XAML流程
  • 故宫的定位
  • 实验五、路由器广域网HDLC 封装配置
  • 熬夜人必看
  • 爱立信:用什么保持全球老大的地位?
  • 升级了Windows Live Essentials 2011,赞
  • [程序安装包制作] Advanced Installer 备忘
  • DR与主/从路由器的区别
  • Linq to entity 中 实现 Sql 中的like 的两个方法小解
  • DIV垂直居中的各种方法
  • unicode变形一句话突破web防火墙过滤
  • Silverlight for Windows Phone Toolkit升级 新增四个控件
  • 英文书信常用语
  • 栽下愉悦也需勤
  • 【跃迁之路】【585天】程序员高效学习方法论探索系列(实验阶段342-2018.09.13)...
  • Angular 2 DI - IoC DI - 1
  • Go 语言编译器的 //go: 详解
  • Idea+maven+scala构建包并在spark on yarn 运行
  • JS函数式编程 数组部分风格 ES6版
  • Next.js之基础概念(二)
  • PaddlePaddle-GitHub的正确打开姿势
  • Python学习之路16-使用API
  • Redis中的lru算法实现
  • spring boot下thymeleaf全局静态变量配置
  • tweak 支持第三方库
  • ViewService——一种保证客户端与服务端同步的方法
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 订阅Forge Viewer所有的事件
  • 对象引论
  • 官方新出的 Kotlin 扩展库 KTX,到底帮你干了什么?
  • 缓存与缓冲
  • 京东美团研发面经
  • 离散点最小(凸)包围边界查找
  • 前端相关框架总和
  • 如何合理的规划jvm性能调优
  • 入门到放弃node系列之Hello Word篇
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 一文看透浏览器架构
  • 如何用纯 CSS 创作一个货车 loader
  • 组复制官方翻译九、Group Replication Technical Details
  • ​什么是bug?bug的源头在哪里?
  • (4) openssl rsa/pkey(查看私钥、从私钥中提取公钥、查看公钥)
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (Note)C++中的继承方式
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • (原創) 未来三学期想要修的课 (日記)
  • (原創) 物件導向與老子思想 (OO)
  • (转)程序员疫苗:代码注入
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • .net 前台table如何加一列下拉框_如何用Word编辑参考文献
  • .net 使用$.ajax实现从前台调用后台方法(包含静态方法和非静态方法调用)
  • .net 使用ajax控件后如何调用前端脚本
  • .Net环境下的缓存技术介绍