EXT2.1的PropertyGrid不支持store动态绑定的折中解决办法

官方说PropertyGrid的store属性应该隐去的
在svn里面已经隐去了
但是docs里还有
他们说因为什么原因所以这个只是个隐含属性,我忘记了
折中解决如下:


x.xml

<dataset>
<property><name>x</name><value>1</value></property>
<property><name>S</name><value>2</value></property>
</dataset>


js

var record = Ext.data.Record.create([
    {name: 'name', mapping : "name"},
    {name: 'value', mapping : "value" }
  ]);


  var pstore = new Ext.data.Store({
    url: 'x.xml',
    reader: new Ext.data.XmlReader({record: 'property'}, record),
    autoLoad: true,
    listeners: {
      load: function(store, records){

        PPGsource = {};

        for(var i = 0; i < records.length; i++){
          PPGsource[records[i].get('name')]=records[i].get('value');
        }

        propertyGrid = new Ext.grid.PropertyGrid({
          width:700,
          autoHeight:true,
          frame: false,
          source: PPGsource
        });

                                     propertyGrid.render("x-www.dc9.cn");

      }
    }
  });


真的,用监听的方式就好啦
然后取值用alert(PPGsource[records[0].get(‘name’)]);
或者alert(PPGsource["x"]);
就好啦~
easy.

7 comments

  1. Quake 说道:

    虽然看不懂 还是赞一个

  2. Quake 说道:

    虽然看不懂“还是赞一个
    我在你写的ASP文件中看到你的QQ
    FUNCTION/c_validcode.asp
    然后就查找到你个人主页了

  3. Y.S 说道:

    这个方法似乎无法读取XML文件中的中文字符。

    存在中文字符的情况下records.length = 0。

    获取propertyGrid的值的问题令我非常困扰,希望能和你探讨下。

  4. Y.S 说道:

    重新验证了一遍,确实存在这个问题。

    包括使用全角空格也会造成读取行数为0

  5. Y.S 说道:

    我刚接触Ext,2.0中是否支持PropertyGrid动态绑定Store?

    为什么开发组又要取消这一特性呢?通用的数据处理方法应该更理想才对。

  6. Y.S 说道:

    原来只需要定义一下source对象,propertyGrid中属性值改变的时候source对象中的相应值就会发生改变,想要获得propertyGrid的值则仅仅需要直接从这个对象中读取数值即可。

    居然是这么简单容易的方法……我花了两天时间到处找这个问题的解决方案,快哭了……

  7. Y.S 说道:

    仔细看了下,你的方案的原理也是如此,仅仅建立了一个source对象。。。

    你的例子可以这样写:

    var PPGsource = {
    ‘x’ : ’1′,
    ‘s’ : ’2′,
    };
    propertyGrid = new Ext.grid.PropertyGrid({
    width:700,
    autoHeight:true,
    frame: false,
    source: PPGsource
    });

    要读取的话只需要这样:
    alert(PPGsource['x']);

    很简单吧-_-!!!!!!!!!!!!!!!!!!

发表评论

电子邮件地址不会被公开。