Javascript Sencha新记录id检索
我经常需要对sencha问题的建议。我想用一个表单创建一个新的记录/模型,这真的很好用。但在回调中(保存记录后),我需要新保存的记录ID——但数据库中已经存在的ID——我得到的是一个自动分配的sencha ID,如“ext-record-465” 代码如下:Javascript Sencha新记录id检索,javascript,extjs,sencha-touch-2,Javascript,Extjs,Sencha Touch 2,我经常需要对sencha问题的建议。我想用一个表单创建一个新的记录/模型,这真的很好用。但在回调中(保存记录后),我需要新保存的记录ID——但数据库中已经存在的ID——我得到的是一个自动分配的sencha ID,如“ext-record-465” 代码如下: 型号: Ext.define('aBMin.model.Ticket', { extend : 'Ext.data.Model', require : ['aBMin.model.Project', 'aBMin.model.Client
型号:
Ext.define('aBMin.model.Ticket', {
extend : 'Ext.data.Model',
require : ['aBMin.model.Project', 'aBMin.model.Client'],
config : {
fields : [{
name : 'ticketid',
type : 'int'
}, {
name : 'clientid',
type : 'int'
}, {
name : 'projectid',
type : 'int'
}, {
name : 'subject',
type : 'string'
}, {
name : 'datecreated',
type : 'string'
}, {
name : 'datemodified',
type : 'string'
}, {
name : 'percentCompleted',
type : 'string'
}, {
name : 'ticketdesc',
type : 'string'
}, {
name : 'supportstaffid',
type : 'int'
}, {
name : 'timeestimate',
type : 'int'
}, {
name : 'eta',
type : 'date'
}, {
name : 'warrantysupport_yn',
type : 'string'
}, {
name : 'ourfault_yn',
type : 'string'
}, {
name : 'ticketstatusid',
type : 'int'
}, {
name : 'clientemailid',
type : 'int'
}, {
name : 'clientname',
type : 'string'
}, {
name : 'total',
type : 'int'
}],
idProperty : 'ticketid',
proxy : {
type : 'direct',
reader : {
type : 'json'
},
api : {
read : Ticket.readMobile,
update : Ticket.updateMobile,
create : Ticket.createMobile
}
},
associations : [{
type : 'belongsTo',
model : 'aBMin.model.Project',
primaryKey : 'projectid',
foreignKey : 'projectid',
associationKey : 'Project',
getterName : 'getProject'
}, {
type : 'belongsTo',
model : 'aBMin.model.Client',
primaryKey : 'clientid',
foreignKey : 'clientid',
associationKey : 'Client',
getterName : 'getClient'
}/*,{
type : 'belongsTo',
model : 'aBMin.model.TicketStatus',
primaryKey : 'ticketstatusid',
foreignKey : 'ticketstatusid',
associationKey : 'TicketStatus',
getterName : 'getTicketStatus'
}*/],
validations : [{
type : 'presence',
field : 'projectid'
}, {
type : 'presence',
field : 'subject',
}, {
type : 'presence',
field : 'clientid',
}, {
type : 'presence',
field : 'ticketdesc'
}, {
type : 'presence',
field : 'supportstaffid',
}, {
type : 'presence',
field : 'eta',
}, /*{
type : 'presence',
field : 'timeestimate',
}
,*/ {
type : 'presence',
field : 'ticketstatusid',
}]
}
});
控制器(创建方法):
我尝试使用record.load方法,但要加载它,我需要我没有的ID。。。有什么办法可以刷新新创建的记录并从数据库中获取其ID吗?服务器应该返回已创建记录的数据,与读取操作返回的数据相同
如果您支持批处理操作(即一次编辑多个记录),那么还应该在每个记录的数据中包含Ext生成的id,在中配置的属性中。服务器返回什么?老实说,我没有返回任何内容-我应该返回新id吗?
case 'Create':
var estimatedtime = parseInt(this.getTicketViewEstymateHours().getValue()) * 60 + parseInt(this.getTicketViewEstymateMinutes().getValue());
record.set(form.getValues());
record.set('timeestimate', estimatedtime);
var validation_errors = record.validate().all;
if(!validation_errors.length) {
record.save({
success : function(record) {
if(record.get('clientemailid') != 0) glob.getEmailViewSubmitCreateTicket().setHidden(true);
Ext.getStore('Ticket').load();
Ext.getStore('TicketSF').load( {
params : {
clientid : record.get('clientid')
,filter : ''
,pagin_from : 0
,pagin_to : 10000
}
} );
getEmailViewTicketField.setValue(record.get('ticketid'));
nav.pop();
Ext.Msg.alert('MESSAGE', 'Ticket has been created.', Ext.emptyFn);
},
failure : function() {
Ext.Msg.alert('MESSAGE', 'Ticket has NOT been crated.', Ext.emptyFn);
});
}
else {
Ext.Msg.alert('MESSAGE', 'You have to fill all required fields', Ext.emptyFn);
for(itm in this.getTicketViewFieldset().getItems().items) {
this.getTicketViewFieldset().getItems().items[itm].removeCls("msg_baddatainputed");
}
for(err in validation_errors) {
for(itm in this.getTicketViewFieldset().getItems().items) {
if(this.getTicketViewFieldset().getItems().items[itm].getName() === validation_errors[err].getField()){
this.getTicketViewFieldset().getItems().items[itm].addCls("msg_baddatainputed");
}
}
}
}
break;