[英]Why my simple ExtJS data example with associations does not work?
從我的角度來看,我在ExtJS中使用關聯建立了最簡單的模型方法。
型號: Post - hasOne- > User
我做了什么:
Post.load(...)
加載post對象。 但是當我嘗試獲取用戶對象時,它沒有正確加載:
(這里是完整的來源: http : //jsfiddle.net/7XRw4/4/ )
Ext.define('Post', {
extend: 'Ext.data.Model',
fields: ['user_id', 'content'],
hasOne: 'User',
proxy: {
type: 'memory',
data: {
posts: [
{id:1, user_id:1, content:'foo'},
{id:2, user_id:1, content:'bar'}
]
},
reader: {
type: 'json',
root: 'posts'
}
}
});
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['name'],
proxy: {
type: 'memory',
data: {
users: [
{id:1, name:'hans'},
{id:2, name:'klaus'}
]
},
reader: {
type: 'json',
root: 'users'
}
}
});
Ext.onReady(function() {
console.log("Ext.onReady() invoked...");
Post.load('1', {
success: function(record, operation) {
thePost = record;
console.log('thePost:', thePost);
theUser = thePost.getUser();
console.log('theUser:', theUser);
alert('The user name: ' + theUser.get('name'));
// The user object will not be right loaded! Why?
}
});
});
.getUser不是異步的嗎? 意味着您應該為其提供成功功能,並在該成功功能中提醒用戶名稱?
但是我在Ext中的hasOne關系中遇到了很多問題。 文檔,教程,文檔注釋-如果您未在json中發送完整的關系,它們將永遠無法達成共識,並且沒有任何用處。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.