gpt4 book ai didi

javascript - 如何使用字符串引用 extJS 组合框?

转载 作者:行者123 更新时间:2023-12-03 10:00:50 24 4
gpt4 key购买 nike

有什么方法可以通过字符串引用组合框的实例吗?
我有一个解决方法,但对此不太满意,特别是当我看到将来需要创建更多组合框时。
我尝试使用“reference”、“id”、“itemId”,但没有成功。

我问的原因是因为我正在转储有关我的字段的元信息,而元信息以字符串的形式出现。
这很有效,直到我需要一个 javascript 实例作为我的“编辑器”。

当信息包含引号时,我无法引用 JavaScript 实例。
我在下面发布我的代码(只是相关部分),并在我的问题/问题/解决方法附近发表评论。

var my_combo=Ext.create('Ext.form.field.ComboBox', {
listClass: 'x-combo-list-small',
store: ['string', 'int', 'number', 'boolean', 'date'],
queryMode: 'local',
displayField: 'data_type',
valueField: 'data_type'
});

var center_grid = Ext.create('Ext.grid.Panel', {
store: ourrecordstore,
region: 'center',
selModel: Ext.create('Ext.selection.CheckboxModel'),
selType: 'rowmodel',
/*
columns: {{grid_panel_columns|safe}},// <---this does not work b/c we need to use javascript variable, not something quoted.
if we could use a string to identify the data_type_combo object, that would be ideal.
for now i am iterating across the dictionary and if the editor i want is data_type_combo, then i have code below to use the data_type_combo instance
previously what you see on the next line was used (django template), but it failed when i needed to add drop downs via combobox.
columns:[{{grid_panel_columns|safe}}]
*/
columns: [{% for column in grid_panel_columns %}
{% if column.editor == "data_type_combo" %}
{'filter': {'type': 'string'},'text': 'data_type', 'dataIndex': 'data_type','editor':my_combo},
{% else %}
{{column|safe}},
{% endif %}
{% endfor %}],
})

这就是 grid_panel_columns 数组的样子

'grid_panel_columns': [
{'filter': {'type': 'string'}, 'text': 'name', 'dataIndex': 'name', 'editor': 'textfield'},
{'filter': {'type': 'string'}, 'text': 'data_type', 'dataIndex': 'data_type', 'editor': 'data_type_combo'},
{'filter': {'type': 'string'}, 'text': 'active', 'dataIndex': 'active', 'editor': 'textfield'},
{'filter': {'type': 'string'}, 'text': 'id', 'dataIndex': 'id'}
],

最佳答案

我不知道我理解是否正确,但您想要为您的编辑器提供一个特定的组合框,例如 xtype: 'combo'

您可以基于组合框定义一个新的xtype,该组合框可用作编辑器:'data_type_combo

这是一个如何实现这一目标的示例 fiddle :https://fiddle.sencha.com/#fiddle/nup

关于javascript - 如何使用字符串引用 extJS 组合框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30607450/

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