javascrpit-ExtJS使用本地JSON建树,重复加载

问题描述

ExtJS使用本地JSON建树,重复加载
初学Extjs,建树时使用了本地的JSON文件,但出现重复的问题,如图

json如下:

 {success"": truedeps"": [        {id"": 1text"": ""Class 1""leaf"": falsechildren"": [                {id"": 2text"": ""Class 1.1""leaf"": truechildren"": []                }                {id"": 3text"": ""Class 1.2""leaf"": truechildren"": []                }            ]        }        {id"": 4text"": ""Class 2""leaf"": falsechildren"": [                {id"": 5text"": ""Class 2.1""leaf"": truechildren"": []                }            ]        }    ]}

model如下:

 Ext.define('App.model.Dep' {    extend: 'Ext.data.Model'    idProperty: 'depmodel'    fields: [{        name: 'id'        type: 'int'    } {        name: 'text'        type: 'string'    }]});

store:

 Ext.define('App.store.DepTree' {    extend: 'Ext.data.TreeStore'    alias: 'store.deptree'    model: 'App.model.Dep'    autoLoad: false    root: {        id: 0        text: 'root'        leaf: false        expanded: true    }    proxy: {        type: 'ajax'        url: 'data/dep.json'        reader: {            type: 'json'            rootProperty: 'deps'            successProperty: 'success'        }    }    listeners: {        beforeload: function (store operation opts) {            //阻止加载            if (!store._can_load_) {                return false;            }            return true;        }    }});

treepanel:

 Ext.define('App.view.dep.DepTree' {    extend: 'Ext.tree.Panel'    alias: 'widget.deptree'    uses: [        'App.store.DepTree'    ]    title: '部门'    glyph: 0xf0c9    rootVisible: false    lines: true    viewModel: 'dep'    listener: {        beforeload: function () {        }    }    initComponent: function () {        var me = this;        var store = Ext.create('App.store.DepTree');        me.store = store;        me.callParent();    }});

解决方案

http://bbs.csdn.net/topics/390985332

时间: 2024-08-04 13:35:16

javascrpit-ExtJS使用本地JSON建树,重复加载的相关文章

Android读取本地json文件的方法(解决显示乱码问题)_Android

本文实例讲述了Android读取本地json文件的方法.分享给大家供大家参考,具体如下: 1.读取本地JSON ,但是显示汉字乱码 public static String readLocalJson(Context context, String fileName){ String jsonString=""; String resultString=""; try { BufferedReader bufferedReader=new BufferedReade

Android访问assets本地json文件的方法

目的:当App中用到固定的json数据时,如:国家城市列表.班级成员等时,可以将json数据制作为本地json文件存入assets文件夹下. 步骤如下: 1.新建assets文件夹,并将json文件复制到此文件夹中 在main文件夹下新建assets文件,然后再assets文件中新建namelist.json文件夹,将json数据复制到test.json文件中. 2.访问json文件 try { AssetManager assetManager = getAssets(); // 获得asse

实用ExtJS教程100例-011:ExtJS Form 使用JSON数据赋值和取值

上一节中我们演示了ExtJS Form的异步加载和提交数据,本节中我们将演示如何使用JSON数据为ExtJS Form中的字段赋值和取值. 系列ExtJS教程持续更新中,点击查看>>最新ExtJS教程目录 使用JSON数据为字段赋值 var formCmp = this.up("form"); var form = formCmp.getForm(); var userValues = { UserName: "Qi Fei", Email: "

不开webServer让chrome能读取本地json等文件

PS:一些测试页面偶尔会加载本地的json文件,没有开web server一般不能访问-不一定每次都要开nginx或apache解决, chrome可以加启动参数"allow-file-access-from-files" Using –disable-web-security switch is quite dangerous! Why disable security at all while you can just allow XMLHttpRequest to access

ExtJs之 Ext.JSON

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <!DOCTYPE html> <html> <head>     <title>ExtJs</title>         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>         &l

ExtJS中格式化json显示

, { xtype: 'button', text: '格式化', iconCls: 'icon-edit', colspan: 2, width: 100, margin: "-23 0 0 70", listeners: { 'click': { fn: this.formatJson, scope: this } } } formatJson : function(options) { var dataform = this.down('dataform'); var json=

ExtJs实践

假如我们程序中有产品(Product)和产品分类(Category)这2个类,前端使用 ExtJs,通过JSON格式同后端进行通讯: public class Category { public string Id { get; set; } public string Name { get; set; } } public class Product { public string Id { get; set; } public string Name { get; set; } public

精通Grails: 用JSON和Ajax实现异步Grails

本文讨论 Grails 对于其互补技术 JSON 和 Ajax 的支持.在前几期的 精通 Grails 系列文章中, JSON 和 Ajax 都扮演支援者的角色,而这一次,它们担任主角.您将使用内置的 Prototype 库和 Grails <formRemote> 标记发出一个 Ajax 请求.您还将看到一些关于提供本地 JSON 和通过 Web 动态获得 JSON 的例子. 为了进行演示,您将组建一个旅行计划页面,在该页面中,用户可以输入出发地机场和目的地机场. 当机场显示在一个 Goog

HTML5移动应用开发第2章:移动web应用的本地存储

在本文中,您将使用最新 Web 技术开发 Web 应用程序.这里的大多数代码只是 HTML.JavaScript 和 CSS - 任何 Web 开发人员的核心技术.需要的最重要的东西是用于测试代码的浏览器.本文中的大多数代码将运行在最新的桌面浏览器上,例外的情况会指出来.当然,还必须在移动浏览器上进行测试,您肯定希望最新的 iPhone 和 Android SDK 支持这些代码.本文中使用的是 iPhone SDK 3.1.3 和 Android SDK 2.1. 本地存储基础 Web 开发人员