Extjs 在架构配置的代理URL中使用自定义函数
当我为模型定义基类时,我可以使用默认代理配置配置模式:Extjs 在架构配置的代理URL中使用自定义函数,extjs,extjs5,Extjs,Extjs5,当我为模型定义基类时,我可以使用默认代理配置配置模式: Ext.define('App.model.Base', { extend : 'Ext.data.Model', idProperty : 'ID', schema : { namespace : 'App.model', proxy : { type : 'rest', url : '{prefix}/{entityNa
Ext.define('App.model.Base', {
extend : 'Ext.data.Model',
idProperty : 'ID',
schema : {
namespace : 'App.model',
proxy : {
type : 'rest',
url : '{prefix}/{entityName:lowercase}'
}
}
});
其中:url
中的小写字母是Ext.util.Format函数
如何在此处使用自定义函数或在构造中配置它,以便将entityName作为变量并对其进行转换(例如在单词之间添加破折号)?您可以在模型构造函数中执行此操作,如下所示:
Ext.define('App.model.Base', {
extend : 'Ext.data.Model',
idProperty : 'ID',
constructor: function(config) {
// Check your config properly
if(config) {
// Your function to build url
var buildUrl = function (data) {
// Do stuff
}
Ext.apply(this, {
schema : {
namespace : 'App.model',
proxy : {
type : 'rest',
url : buildUrl(config)
}
}
});
}
this.callParent(arguments);
}
});
Ext.create('App.model.Base', {
// Your url config
prefix: ...,
entityName: ...,
...
});
创建App.model.Base的新实例,如下所示:
Ext.define('App.model.Base', {
extend : 'Ext.data.Model',
idProperty : 'ID',
constructor: function(config) {
// Check your config properly
if(config) {
// Your function to build url
var buildUrl = function (data) {
// Do stuff
}
Ext.apply(this, {
schema : {
namespace : 'App.model',
proxy : {
type : 'rest',
url : buildUrl(config)
}
}
});
}
this.callParent(arguments);
}
});
Ext.create('App.model.Base', {
// Your url config
prefix: ...,
entityName: ...,
...
});
您可以在模型构造函数中执行此操作,如下所示:
Ext.define('App.model.Base', {
extend : 'Ext.data.Model',
idProperty : 'ID',
constructor: function(config) {
// Check your config properly
if(config) {
// Your function to build url
var buildUrl = function (data) {
// Do stuff
}
Ext.apply(this, {
schema : {
namespace : 'App.model',
proxy : {
type : 'rest',
url : buildUrl(config)
}
}
});
}
this.callParent(arguments);
}
});
Ext.create('App.model.Base', {
// Your url config
prefix: ...,
entityName: ...,
...
});
创建App.model.Base的新实例,如下所示:
Ext.define('App.model.Base', {
extend : 'Ext.data.Model',
idProperty : 'ID',
constructor: function(config) {
// Check your config properly
if(config) {
// Your function to build url
var buildUrl = function (data) {
// Do stuff
}
Ext.apply(this, {
schema : {
namespace : 'App.model',
proxy : {
type : 'rest',
url : buildUrl(config)
}
}
});
}
this.callParent(arguments);
}
});
Ext.create('App.model.Base', {
// Your url config
prefix: ...,
entityName: ...,
...
});