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"]);


原來只需要定義一下source對象,propertyGrid中屬性值改變的時候source對象中的相應值就會發生改變,想要獲得propertyGrid的值則僅僅需要直接從這個對象中讀取數值即可。


居然是這麼簡單容易的方法……我花了兩天時間到處找這個問題的解決方案,快哭了……

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

要讀取的話只需要這樣:
alert(PPGsource['x']);
發佈了51 篇原創文章 · 獲贊 0 · 訪問量 2506
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章