【问题标题】:How to get custom data in a combo box如何在组合框中获取自定义数据
【发布时间】:2013-05-21 19:24:45
【问题描述】:

我正在尝试使用项目名称列表填充组合框。我能够成功获取所有项目名称,但我似乎无法弄清楚如何将它们作为自定义数据集添加到组合框中。我已经研究过使用其他类型的组合框(迭代、组合、属性等),但它们似乎没有将自定义数据添加到下拉列表中的功能(除非我弄错了)。这是我用于组合框的代码:

this.down = this.add({
    xtype: 'rallycombobox',
    storeConfig: [{
        model: 'Project',
        autoLoad: true,
        fieldLabel: 'Projects:',
        data: this.project_names,
        width: field_width
    }]
});

尝试使用此代码运行时,我收到“未捕获的类型错误:无法调用未定义的方法 'getProxy'。我不知道如何让它工作。我也尝试过以下方法:

this.down = this.add({
    xtype: 'rallycombobox',
    model: 'Project',
    fieldLabel: 'Projects:',
    data: this.project_names,
    width: field_width
});

我仍然会遇到同样的错误。谁能帮我解决我做错的事情?谢谢!

【问题讨论】:

    标签: javascript rally


    【解决方案1】:

    如果您手头已有要在 ComboBox 中使用的项目列表,而不是 Rally ComboBox,我建议您只使用 Ext ComboBox。 Rally ComboBox 旨在通过查询来自 Rally 的数据来填充其存储 - 因此,当您尝试将 Rally WSAPI 存储与本地数据混合匹配时,您会看到getProxyerror。

    设置可能如下所示。

    // The data store containing the list of Projects
    var projectStore = Ext.create('Ext.data.Store', {
        fields: ['_ref', 'Name'],
        data : [
            {"_ref": "/project/12345678910", "Name": "Project 1"},
            {"_ref": "/project/12345678911", "Name": "Project 2"},
            {"_ref": "/project/12345678912", "Name": "Project 3"}
            //...
        ]
    });
    
    // Create the combo box, attached to the Projects data store
    this.projectSelector = Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose Project',
        store: projectStore,
        queryMode: 'local',
        displayField: 'Name',
        valueField: '_ref',
        listeners:{
             scope: this,
             select: function(combobox) {
                // Do stuff here
                console.log('Ref of Project Selected: ' + this.projectSelector.getValue());
    
            }
        }
    });
    
    this.down('#projectSelectorContainer').add(this.projectSelector); 
    

    希望这会有所帮助。如果有后续问题,请告诉我们。

    【讨论】:

    • 在创建数据存储时是否可以在data 字段中获取我在(在拉力赛中)当前项目中的所有项目的列表?
    【解决方案2】:

    这可能会对您有所帮助:

    Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    
    launch: function() {
        //Write app code here
    
        var projectStore = Ext.create('Rally.data.WsapiDataStore',{
            model: 'project',
            fetch: ['Name','ObjectID'],
            autoLoad: true,
            // filters:[{
                // property:'ObjectID',
                // operator:'=',
                // value: __PROJECT_OID__
            // }],
    
    
            listeners:{
                load: function(store,records,success){
                    this._updateCombo(store);
                },
                scope: this
    
            }
    
    
    
        });
        console.log('/project/',__PROJECT_OID__);
    },
    
    _loadCombo: function(myStore){
    
        this._myCombo = Ext.create('Ext.form.ComboBox',{
            fieldLabel: 'Choose Project',
            store: myStore,
            queryMode: 'remote',
            displayField: 'Name',
            valueField: 'Name',
            listeners: {
                select: function(combobox,records){
                    console.log(records[0]["data"]["Name"]);
                }
            },
            scope:this
    
        });
        this.add(this._myCombo);
    
    },
    _updateCombo: function(myStore){
        if(this._myCombo === undefined){
            this._loadCombo(myStore);
        }else{
            this._myCombo.clearValue();
        }
    
    }
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      相关资源
      最近更新 更多