0
在ExtJS 6.2.1中,我試圖通過使用model.load()函數來獲取記錄,並且我正在關注Ext.data.Model doc「使用代理服務器」部分的示例。ExtJs加載模型ID
這是我的用戶模型:
Ext.define('myapp.model.User', {
extend: 'Ext.data.Model',
fields: [
'id',
'name',
'email'
],
proxy: {
type: 'ajax',
api: {
read: '/user'
},
reader: {
type: 'json',
rootProperty: 'data'
}
}
});
並在視圖,我試圖加載用戶其ID = 1
var user = Ext.create('myapp.model.User');
user.load(1,{
//scope: this,
callback: function(record, operation, success) {
Ext.getCmp('name').setHtml(record.get('name'));
Ext.getCmp('email').setHtml(record.get('email'));
}
});
但它並沒有將請求發送到/ user/1,它向/用戶發送了一個請求
我也嘗試了一種不同的方法,在創建用戶實例時設置了id,並引用了User模型中的id,但它無法獲得ID。
如果我在URL中對ID進行硬編碼,它可以得到結果,所以主要問題是如何獲取ID。
var user = Ext.create('myapp.model.User',{id:1});
user.load({
//scope: this,
callback: function(record, operation, success) {
Ext.getCmp('name').setHtml(record.get('name'));
Ext.getCmp('email').setHtml(record.get('email'));
}
});
proxy: {
type: 'ajax',
api: {
read: '/user/1' // this is working
//read: '/user/' + this.id // undefined
//read: '/user/' + this.get('id') //got error: this.get is not a function
},
reader: {
type: 'json',
rootProperty: 'data'
}
}
這樣做的適當方法是什麼?我必須創建一個商店嗎?