【问题标题】:Ext 4.1.1: Add new record to StoreExt 4.1.1:向 Store 添加新记录
【发布时间】:2012-07-18 15:38:10
【问题描述】:

我想在商店初始化后添加记录。

我尝试了loadData()loadRawData()add(),但没有任何接缝可以工作。

这是我的 jsfiddle:http://jsfiddle.net/charlesbourasseau/zVvLc

有什么想法吗?

【问题讨论】:

    标签: extjs combobox store extjs4.1


    【解决方案1】:

    对于面板,您可以通过remove()add() 添加或删除项目

    var store = Ext.create('MyApp.store.Roles', {autoLoad: false});
    store.load(function(records, action, success) {
        if (success) {
            store.remove(store.findRecord('id', 50, 0, false, true, true));//exact match
            store.add({'id':110,'name':'Agent' });
        }
    });
    

    【讨论】:

      【解决方案2】:

      您需要在组合框中设置queryMode: 'local'。最小的例子:

      Ext.onReady(function() {
          var store = Ext.create('Ext.data.Store', {
              alias: 'store.ModeStore',
              autoLoad: false,
              fields: [{
                  name: 'mode',
                  type: 'string'
              }, {
                  name: 'id',
                  type: 'string'
              }],
              data: [{
                  mode: 'mode1',
                  id: 1
              }]
          });
      
          var container = Ext.create('Ext.form.field.ComboBox', {
              renderTo: Ext.getBody(),
              displayField: 'mode',
              valueField: 'mode',
              store: store,
              queryMode: 'local'
          });
      
          store.add({
              mode: 'mode2',
              id: 2
          });
      }); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-15
        • 2011-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多