Cookies 从cookie中选择Combobox中的值

Cookies 从cookie中选择Combobox中的值,cookies,extjs,combobox,Cookies,Extjs,Combobox,程序员们 我想做以下工作:在屏幕上,用户可以在组合框中选择值。这些值存储在cookie中,以便在会话中稍后访问同一页面时可以恢复。Cookie工作发现,ExtJs做得很好。组合框是服务器绑定的,打开时将检索它们的记录。这意味着,在恢复cookie值时,所需的记录可能不存在。从服务器检索记录不是一个解决方案,因为组合框是分页的,要准确地确定我必须加载哪个页面会很麻烦 我尝试了以下解决方案: if(cookie.cobblerContactId != null) { var recD

程序员们

我想做以下工作:在屏幕上,用户可以在组合框中选择值。这些值存储在cookie中,以便在会话中稍后访问同一页面时可以恢复。Cookie工作发现,ExtJs做得很好。组合框是服务器绑定的,打开时将检索它们的记录。这意味着,在恢复cookie值时,所需的记录可能不存在。从服务器检索记录不是一个解决方案,因为组合框是分页的,要准确地确定我必须加载哪个页面会很麻烦

我尝试了以下解决方案:

if(cookie.cobblerContactId != null) {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Achternaam', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.cobblerContactId,
            Achternaam: cookie.CobblerContactName
        });           
        behandelaarStore.add(rec);
        behandelaarCombo.setValue(cookie.cobblerContactId);
        behandelaarCombo.render();
        //editForm.render();
    }
如您所见,我人工创建了记录,将其添加到数据存储并选择它。问题是组合框没有显示正确的值,它显示为未选中。打开后,它将从服务器检索25条记录的第一页。我还尝试了-commented out-editForm.render(),但也没有成功。直接在组合框(cookie.CobblerContactName)中写入文本不起作用,我尝试了selectText(),但似乎有所不同。如果我只使用selectValue(),它将显示Id,而不是文本,因为数据存储还没有具有该Id的记录


我已经试了两天了,但都没能成功。有人有解决方案吗?

尝试设置
forceSelection:false
,然后您可以设置不在列表中的文本。

forceSelection似乎与此无关,因为我在随后选择的数据存储中添加了一条真正的新记录。因此,显示的文本与实际记录相对应。我现在已经开始工作了

function getCookie() {
    if(Ext.util.Cookies.get('ticketIndexFilter') == null)
        return;
    var filterSet = Ext.ComponentMgr.get('additionalFilterSet');    
    var cookie = Ext.decode(Ext.util.Cookies.get('ticketIndexFilter'));
    txtNummer.setValue(cookie.TicketNr);
    if(cookie.datumVan != null && cookie.datumVan != ""){
        datVan.setValue(cookie.datumVan.substr(0, 10));
        filterSet.expand();
    }
    if(cookie.datumTm != null && cookie.datumTm != ""){
        datTm.setValue(cookie.datumTm.substr(0, 10));
        filterSet.expand();
    }
    if(cookie.relationId != null && cookie.relationId != "") {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Name', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.relationId,
            Name: cookie.relationName
        }, cookie.relationId);           
        relatieStore.add(rec);
        relatieCombo.setValue(cookie.relationId);
    }
    if(cookie.cobblerContactId != null && cookie.cobblerContactId != "") {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Achternaam', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.cobblerContactId,
            Achternaam: cookie.cobblerContactName
        }, cookie.cobblerContactId);           
        behandelaarStore.add(rec);
        behandelaarCombo.setValue(cookie.cobblerContactId);
        filterSet.expand();
    }
    if(cookie.statusId != null && cookie.statusId != "") {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Naam', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.statusId,
            Naam: cookie.statusName
        }, cookie.statusId);           
        statusStore.add(rec);
        statusCombo.setValue(cookie.statusId);
        filterSet.expand();
    }
    if(cookie.priorityId != null && cookie.priorityId != "") {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Naam', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.priorityId,
            Naam: cookie.priorityName
        }, cookie.priorityId);           
        prioriteitStore.add(rec);
        prioriteitCombo.setValue(cookie.priorityId);
        filterSet.expand();
    }
    if(cookie.relationContactId != null && cookie.relationContactId != "") {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Achternaam', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.relationContactId,
            Achternaam: cookie.relationContactName
        }, cookie.relationContactId);           
        contactStore.add(rec);
        contactCombo.setValue(cookie.relationContactId);
        filterSet.expand();
    }
    if(cookie.categoryId != null && cookie.categoryId != "") {
        var recDef = Ext.data.Record.create([
            {name: 'Id', type: 'int'},
            {name: 'Naam', type: 'string'}
        ]);
        var rec = new recDef({
            Id: cookie.categoryId,
            Naam: cookie.categoryName
        }, cookie.categoryId);           
        categorieStore.add(rec);
        categorieCombo.setValue(cookie.categoryId);
        filterSet.expand();
    }
    //finally, an easy one
    opgelostBox.setValue(cookie.finalized);
}

function setCookie(){
    var filterPresets = {
        TicketNr: txtNummer.getValue(),
        datumVan: datVan.getValue(),
        datumTm: datTm.getValue(),
        relationId: relatieCombo.getValue(),
        relationName: relatieCombo.getValue() == "" ? null : relatieStore.getById(relatieCombo.getValue()).get('Name'),
        cobblerContactId: behandelaarCombo.getValue(),
        cobblerContactName: behandelaarCombo.getValue() == "" ? null : behandelaarStore.getById(behandelaarCombo.getValue()).get('Achternaam'),
        statusId: statusCombo.getValue(), 
        statusName: statusCombo.getValue() == "" ? null : statusStore.getById(statusCombo.getValue()).get('Naam'),
        priorityId: prioriteitCombo.getValue(),
        priorityName: prioriteitCombo.getValue() == "" ? null : prioriteitStore.getById(prioriteitCombo.getValue()).get('Naam'),
        relationContactId: contactCombo.getValue(),
        relationContactName: contactCombo.getValue() == "" ? null : contactStore.getById(contactCombo.getValue()).get('Achternaam'),
        categoryId: categorieCombo.getValue(),
        categoryName: categorieCombo.getValue() == "" ? null : categorieStore.getById(categorieCombo.getValue()).get('Naam'),
        finalized: opgelostBox.getValue()            
    };
    Ext.util.Cookies.set('ticketIndexFilter', Ext.encode(filterPresets));        
}
当用户按下搜索按钮时,将调用setCookie。在Ext.OnReady中调用getCookie以预设控件。我花了将近10个小时来计算,所以我想我应该和大家分享


第一篇帖子包含错误:cookie.CobblerContactName而不是cookie.CobblerContactName

forceSelection似乎不是问题所在。我的8个小时一过,我就可以发布这个问题的答案,即让它实际运行的代码。