0
我有一个非常简单的模型/存储/代理REST接口。我遇到的问题是,当我加载商店(通过GET)时,商店似乎将新记录放在内部toCreate列表中 - 所以当我调用sync()时,它会尝试POST它刚刚吸过去的记录。我知道我做了愚蠢的事情,但我已经简化这件事,就像我可以没有运气...使用REST代理的简单模型/商店问题。
型号
Ext.define('sld.model.Org', {
extend: 'Ext.data.Model',
config: {
clientIdProperty: '_id',
fields: [
{ name: '_id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'version', type: 'string' }
]
}
});
与实体店/代理:
Ext.define('sld.store.Orgs', {
extend : 'Ext.data.Store',
config: {
model: 'sld.model.Org',
storeId: 'orgs',
proxy: {
type: 'rest',
url: 'http://127.0.0.1:3003/orgs',
useDefaultXhrHeader:false,
enablePagingParams: false,
limitParam: false,
reader: {
type: 'json',
rootProperty: 'orgs'
}
}
}
});
顺便说一句,我也是有基本身份验证这样做 - 我不认为这会影响的事情,但为了以防万一,我会包括:
setAuthString: function (username, password) {
authString = 'Basic ' + base64_encode (username + ':' + password);
},
setAuthHeader: function(proxy) {
var header = proxy.getHeaders();
header.Authorization = authString;
proxy.setHeaders(header);
}
因此,当执行加载并在完成时立即调用sync()时,我回头看看添加了8个对象,第一个POST显示在我的服务器端(由于我还没有实现,所以失败了)。
orgsStore.load (function(records, operation, success) {
if (success) {
console.log('loaded orgs count = ' + records.length);
console.log ('does it need a sync?');
var obj = orgsStore.sync();
console.log ('sync returned added ' + obj.added.length + ' and updated ' + obj.updated.length);
} else {
console.log ('failed to load orgs!');
}
}, this);
哪里去追逐任何想法将真棒。