gpt4 book ai didi

javascript - 对象值 Extjs4 的 Celleditor

转载 作者:行者123 更新时间:2023-11-30 18:32:03 25 4
gpt4 key购买 nike

我正在寻找如何执行此操作的最佳解决方案。我有什么:

// model
Ext.define("User", {
extend: "Ext.data.Model",
fields: [
{name: "id", type: "int"},
{name: "name"},
{name: "description", type: "string"}
]
});
// store with data
var oStore = new Ext.data.Store({
model: "User",
data: [
{id: 1, name: {name:"John"}, description: "Fapfapfap"},
{id: 2, name: {name:"Danny"}, description: "Boobooboo"},
{id: 3, name: {name: "Tom"}, description: "Tralala"},
{id: 4, name: {name:"Jane"}, description: "Ololo"},
]
});
// and finally I have a grid panel
Ext.create("Ext.grid.Panel", {
columns: [
{dataIndex: "id", header:"ID"},
{
dataIndex: "name",
header: "Name",
renderer: function(value){return value.name;},
editor: "textfield"},
{dataIndex: "description", header: "Description", flex: 1, editor: "htmleditor"}
],
plugins: [new Ext.grid.plugin.CellEditing({clicksToEdit: 2})],
store: store,
renderTo: document.body
});​

当我双击一个单元格时,我在编辑器字段中看到 [object] Object,当我输入有效值时,我在网格中看到空单元格。

所以,问题是——我如何设置 celleditor 来获取数据而不是从 record.name 而是从 record.name.name

最佳答案

您可以覆盖模型上的getset 方法,因此将支持多级字段名称。以下是实现示例。

Ext.define("User", {
extend: "Ext.data.Model",
fields: [
{name: "id", type: "int"},
{name: "name"},
{name: "description", type: "string"}
],
get: function(key) {
if (Ext.isString(key) && key.indexOf('.') !== -1) {
var parts = key.split('.');
var result = this.callParent([ parts[0] ]);
return result[parts[1]];
}
return this.callParent(arguments);
},
set: function(key, value) {
if (Ext.isString(key) && key.indexOf('.') !== -1) {
var parts = key.split('.');
var result = this.get(parts[0]);
result[parts[1]] = value;

this.callParent([ parts[0], result ]);
return;
}
this.callParent(arguments);
}
});

我不确定商店是否检测到对 name.name 字段所做的更改。如果不是,您可能还应该将记录标记为脏。

工作样本:http://jsfiddle.net/lolo/dHhbR/2/

关于javascript - 对象值 Extjs4 的 Celleditor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com