Extjs系列之 ArrayStore的用法

一個小巧的幫助類,用於更方便的從一個數組的數據來創建Ext.data.Store

Ext.define("diy", {
/**
* 初始化組件
*/
initComponent: function () {
var me = this;
var entity = me.getEntity();
Ext.apply(me, {
header: {
title: ""
},
width: 600,
height: 300,
layout: "fit",
items: [{
id: "editid",
xtype: "form",
autoScroll: true,
layout: {
type: "table",
columns: 2
},
bodyPadding: 5,
defaultType: 'textfield',
fieldDefaults: {
labelAlign: "right",
labelSeparator: "",
msgTarget: 'side',
margin: "5"
},
items: [{
xtype: "hidden",
id: "id",
name: "id",
value: entity == null ? null : entity.get("id"),
}{
id: "editStatus",
allowBlank : false,
blankText : "",
xtype: "combo",//ComboBox就像是傳統的HTML文本 <input> 域和 <select> 域的綜合;
labelAlign: "left",
labelWidth: 60,
labelSeparator: "",
fieldLabel: myproject.Message.Express_State,
value: entity == null ? null : me.store.findRecord("id",entity.get("status")),
store: me.store
}
],
});
me.callParent(arguments);
},
});
store定義如下:

store : Ext.create("Ext.data.ArrayStore", {
fields: ["id", "text"],
data: [[-1, ""], [0, "待發貨"],
[1, "已發貨"], [2, "已收貨"],
]
}),

如果我們通過entity也就是前面表格傳遞進來的實例中只能獲取到諸如id字樣,0,1,2等怎樣轉化成待發貨,已收貨呢

這時候,使用ArrayStore的一個方法叫findRecord(),如上的代碼使用,記住參數id只是因爲我們的field字段中定義了id和text,

如果不是id,別的也可以,findRecord(“自己定義的字段”,相應的值)這樣就可已獲得text字段的值了,

之前也是過getById這個方法()但是我傳遞參數只能傳遞數字,傳遞entity.get(“status”)就不可以,

但是這個方法測試有效

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章