gpt4 book ai didi

javascript - 如何在 Ext JS 中使用当前值进行模板调节?

转载 作者:行者123 更新时间:2023-12-02 22:55:03 27 4
gpt4 key购买 nike

我有这个对象(它是一个带有数组存储的组合框):

        Ext.create('Ext.data.Store', {
storeId: 'votationStore',
fields:[ 'id', 'eligible_for_voting'],
data: [
{ id: 1, eligible_for_voting: true },
{ id: 2, eligible_for_voting: false },
{ id: 3, eligible_for_voting: false },
{ id: 4, eligible_for_voting: false }
]
});

Ext.create('Ext.grid.Panel', {
title: 'Grid',
store: Ext.data.StoreManager.lookup('votationStore'),
columns: [
{ text: 'Number', dataIndex: 'id' },
{
text: 'Can be voted?',
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
return value?'Yes':'No';
},
dataIndex: 'eligible_for_voting',
flex: 1,
editor: {
xtype: 'combobox',
displayField: 'id',
displayTpl: [
'<tpl for=".">',
' <tpl if="values">',
' Yes',
' <tpl else>',
' No',
' </tpl>',
' </tpl>'
],
store: [
true,
false
],
valueField: 'id'
}
}
],
plugins: [
{
ptype: 'cellediting',
clicksToEdit: 1
}
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});

正如您从上面看到的,尽管有键引用,我仍尝试直接访问从商店中选择的值。

模板代码:

   <tpl for=".">
<tpl if="values">
Yes
<tpl else>
No
</tpl>
</tpl>

通常我知道您是否有一个结构化对象,可以使用 if={name_object}

但是如果您想直接访问对象并将其存储为没有键的普通数组怎么办?

额外信息:我也在使用 sencha archer 6.60 版本。

https://fiddle.sencha.com/#view/editor&fiddle/2vk1

集成:我想要实现的是使用 displayTpl 根据我在组合框中选择的内容更改显示的文本模板。

根据我读到的文档,使用 <tpl for=".">允许我直接访问上下文值并在模板中创建指针。与<tpl if="values">我正在尝试接受value通过 for="."提供并访问它,只是为了验证它是真是假。

我想在不定义字段或通过绑定(bind)访问它们的情况下完成此操作,但直接不使用任何引用,例如 {votation.id}或者类似的东西,以防我定义了上面的对象。

这可能吗?

最佳答案

不知道我的理解是否正确。您想在值为 true 时显示 Yes,在值为 false 时显示 No 吗?

检查 fiddle https://fiddle.sencha.com/#view/editor&fiddle/2vnl

关于javascript - 如何在 Ext JS 中使用当前值进行模板调节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58024842/

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