Sencha Javascript插入到数组第一个索引
我正在从我的web服务请求产品。我想在对象数组的第一个索引中插入新项 我的躺椅功能:Sencha Javascript插入到数组第一个索引,javascript,extjs,Javascript,Extjs,我正在从我的web服务请求产品。我想在对象数组的第一个索引中插入新项 我的躺椅功能: NewMobile.globals = { mesaj: 'selam', action: '', server: '192.168.50.70', branchCode: '0', activeTable: '', activeFolio: '0', activeTableGroup: '', activeMustGroup: -1, a
NewMobile.globals = {
mesaj: 'selam',
action: '',
server: '192.168.50.70',
branchCode: '0',
activeTable: '',
activeFolio: '0',
activeTableGroup: '',
activeMustGroup: -1,
activePid: 0,
activeMustGroupString: 0,
activeMustDesc: '',
activeMustArray: [],
activeCampProduct: '',
products: undefined,
rePrint: '',
activePax: 1,
uuid: 'tanimsiz',
activeSkin: 'Krem',
version:undefined,
minVersion:132
};
这是我的要求
NewMobile.globals.products = Ext.create('NewMobile.store.PorductStore');
NewMobile.globals.products.setProxy({url: "http://" + NewMobile.globals.server + ':1002/zulu/newmobile/data.aspx?act=getAllProducts'});
NewMobile.globals.products.getProxy();
NewMobile.globals.products.load(function(a, records, c, d, e){
if (c !== true)
{
Ext.Viewport.setMasked(false);
Ext.Msg.alert('uyarı', NewMobile.message.connectionError, Ext.emptyFn);
return;
}
else
{
if(NewMobile.globals.version!==undefined)
{
if(NewMobile.globals.version.MinorRevision>=NewMobile.globals.minVersion)
{
var PopulerProducts=Ext.create('NewMobile.model.Products',
{ id:-65000,
name:"SIK KULLANILANLAR",
groupId:200000,
color:"#FFC673",
type:1,
order:-1,
mustModGroups:0,
mustModGrpCount:0
}
);
NewMobile.globals.products.unshift(PopulerProducts);
}
}
}
});
产品型号:
Ext.define('NewMobile.model.Products', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field'
],
config: {
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
},
{
name: 'groupId',
type: 'int'
},
{
name: 'price',
type: 'float'
},
{
name: 'color'
},
{
name: 'type',
type: 'int'
},
{
name: 'mustModGrpCount'
},
{
name: 'mustModGroups'
},
{
name: 'order',
type: 'int'
},
{
name: 'campCount',
type: 'int'
},
{
name: 'stockCode'
},
{
name: 'populer',
type: 'boolean'
}
]
}
});
Chrome控制台显示此错误
对象[Object Object]没有方法“unshift”我假设您的
NewMobile.store.PorductStore
正在扩展Ext.store.store
。要向商店添加项目,您可以使用add
或insert
方法
add
将项目添加到商店的末尾,因此您要使用的是insert
,并将索引指定为0。大概是这样的:
myStore.insert(0, newRecord)
要保持排序,请使用addSorted
。根据当前排序信息,将传递的记录插入索引处的存储中
myStore.addSorted(newRecord)
您可以在Ext.js中阅读更多关于如何使用商店的信息:Hi carcel谢谢您的回答。NewMobile.globals.products是我的对象数组,而不是它的存储。我正在对这个数组进行名称升序排序。当我在你的代码运行之前尝试了它,但是我的排序被删除了。你能在问题中添加NewMobile.store.PorductStore的定义吗?使用Store对常规数组来说是一个误导性的名称。添加了lounch功能上我的问题是“sorter”。我尝试了“插入”方法并成功了。但自动增加了分拣机。在插入数组值之前按“字母顺序”,在插入之后添加排序器并按“顺序”排序。如何解决此问题?如果要保持排序并将记录添加到正确的位置,请尝试使用“addSorted”方法。