【问题标题】:How to remove the duplicate value in the store extjs如何删除商店extjs中的重复值
【发布时间】:2013-06-03 18:33:48
【问题描述】:

我想删除此商店中的重复值。

有时,网址会返回一些重复值,我怎样才能删除重复值并仅列出该值 1 次?

var input1store = new Ext.data.Store({
    fields: [{name: 'name'}],
    proxy:{
        type: 'ajax',
        url: 'www.requesturl.com?format=json&source1',
        reader: {
            type: 'json',
            root: 'xml.result'
        }
    },
    autoLoad:false,
    sorters: [{property: 'name', direction: 'asc'}]
});

我根据您的建议编写的代码,但仍然无法正常工作。 Input1store2 应该只包含唯一值。

var input1storeArray = [];
var input1store = new Ext.data.Store({
fields: [{name: 'name'}],
proxy:{
    type: 'ajax',
    url: 'www.requesturl.com?format=json&source1',
    reader: {
        type: 'json',
        root: 'xml.result'
    }
},
autoLoad:false,
sorters: [{property: 'name', direction: 'asc'}],
listeners: {
  load: function(store){
input1storeArray = Ext.Array.unique(store.getRange());
}
  }
});


var input1store2 = new Ext.data.SimpleStore({
field = ['name'],
data =  input1storeArray 
});

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    我认为没有任何内置功能。您需要在模型级别强制执行它 - 使该字段唯一并处理错误,或者加载商店,按该字段排序并检查比较最后一个和下一个的所有记录。

    【讨论】:

    • 我已尝试根据您在此处的建议进行操作。但我无法让它发挥作用。有没有可能你给我一个例子或一个快速代码。谢谢
    • 你能把你的代码贴出来,我会尽力帮你找出错误的吗?
    • 我已经更新了上面的问题,包括收集唯一值的代码,但它似乎不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    相关资源
    最近更新 更多