[英]How to make template conditioning in Ext JS with the current value?
我有這個 object (這是一個帶有數組存儲的 combobox ):
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()
});
正如您從上面看到的,我試圖直接訪問從商店中選擇的值,盡管有鍵 ref。
模板代碼:
<tpl for=".">
<tpl if="values">
Yes
<tpl else>
No
</tpl>
</tpl>
通常我知道如果你有一個結構化的 object 你可以使用 if={name_object}
但是,如果您想直接訪問 object 並將存儲作為沒有鍵的普通數組怎么辦?
額外信息:我也在使用 6.60 版本的 sencha 架構師。
https://fiddle.sencha.com/#view/editor&fiddle/2vk1
集成:我想要實現的是根據我在 combobox 中選擇的內容,使用displayTpl
模板更改顯示的文本。
從我讀到的文檔中,使用<tpl for=".">
允許我直接訪問上下文值並在模板中創建一個指針。 使用<tpl if="values">
我試圖獲取通過 for="." 提供的value
。 並訪問它,只是為了驗證它是真還是假。
我想在不定義字段或通過綁定訪問它們的情況下進行此操作,但直接沒有像{votation.id}
類的任何引用或類似的東西,以防我定義了上部 object。
那可能嗎?
我不知道我是否理解正確。 您想在 value 為true
時顯示Yes
,而在 value 為false
時顯示No
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.