1

Item のフィールド「Answered」が「true」に設定されている Itemtpl にクラスを追加できるようにしたいと思います。簡単に聞こえますが、どこから始めればよいかわかりません。

tpl で Answered が true かどうかを確認する必要があることはわかっていますが、テンプレートの書き方がわかりません.. oO

        //model
    Ext.define('User', {
        extend: 'Ext.data.Model',
        config: {
            idProperty: 'Name',
            fields: [
                {name: 'Name', type: 'string'},
                {name: 'Address', type: 'string'},
                {name: 'ID', type: 'int'},
                {name: 'WebUrl', type: 'string'},
                {name: 'InfoUrl', type: 'string'},
                {name: 'Answered', type: 'boolean'},
                ]
        }
    });

    //store

    aStore = Ext.create('Ext.data.Store', {
        model: 'User',
        sorters: 'Name',
        grouper: {
            groupFn: function(record) {
                return record.get('Name')[0];
            }
        }
    });

    //full store

    store = Ext.create('Ext.data.Store', {
        model: 'User',
        sorters: 'Name',
        grouper: {
            groupFn: function(record) {
                return record.get('Name')[0];
            }
        },
        proxy: {
            type: 'ajax',
            url: '/Services/RestaurantList.ashx',
            reader: {
                type: 'json',
                rootProperty: 'users'
            }
        },
        listeners:{
            load: function(){
                var all = store.data.all;
                aStore.setData(all.slice(0,30));
            }
        },
        autoLoad: true
    });


    //the list
    list = Ext.create('Ext.List', {
        flex: 8,
        itemTpl: ['<div class="contact">{Name}</div>'],
        store: aStore,
        listeners: {
            itemtap: function(list, index, target, record) {
                mainContainer.setActiveItem(1);
                detailsPanel.setRecord(record);
        },
        plugins: [
            {
                xclass: 'Ext.plugin.PullRefreshFn',
                refreshFn: function(){
                    store.clearData();
                    aStore.clearData();
                    store.clearFilter();
                    aStore.clearFilter();
                    store.load();
                    list.refresh();
                }
            }
        ],
        grouped: true
    });
4

1 に答える 1

3

XTemplate のドキュメントを見ましたか? http://docs.sencha.com/touch/2.2.1/#!/api/Ext.XTemplate . 特に、「基本的な比較演算子による条件付き処理」セクションを見てください。

表記法を使用したくない場合は<tpl if="">、三項演算子も使用できます。

itemTpl: new Ext.XTemplate(
    '<div class="{[values.Answered ? \'answered\' : \'\']}">{Name}</div>'
),
...
于 2013-09-04T13:15:01.293 に答える