我在網上到處查看了一些東西,但我似乎無法找到在Est Js 4模型中實現多對多關聯的方法。以原型爲例。我有一個「帖子」和「標籤」的應用程序。我如何在Ext Js 4模型中表示這一點,並通過標籤和帖子過濾標籤?在Ext中實現ManyToMany關聯Js 4
2
A
回答
4
ManyToMany意味着有一些額外的表(或數組)包含A和B之間的鏈接。因此,實現這一點的唯一方法是使用額外的存儲。
在有很多的項目,每個人都可以屬於多個類別的情況下,這裏的模型定義:
Ext.define('BS.model.Item', {
extend: 'Ext.data.Model',
fields: [
{name: 'name' , type: 'string'},
],
proxy: {
type: 'direct',
api: {
create: Items.Create,
read: Items.GetTree,
update: Items.Update,
destroy: Items.Delete,
},
},
hasMany: {model: 'BS.model.ItemInCategory', name: 'categories', foreignKey: 'itemId'},
});
Ext.define('BS.model.ItemCategory', {
extend: 'Ext.data.Model',
fields: [
{name: 'name' , type: 'string'},
],
proxy: {
type: 'direct',
api: {
create: ItemCategories.Create,
read: ItemCategories.Read,
update: ItemCategories.Update,
destroy: ItemCategories.Delete,
},
},
});
Ext.define('BS.model.ItemInCategory', {
extend: 'Ext.data.Model',
fields: ['itemId', 'categoryId'],
// This will allow create operations with multiple records
clientIdProperty: 'clientId',
proxy: {
type: 'direct',
api: {
create: ItemInCategory.Create,
read: ItemInCategory.Read,
destroy: ItemInCategory.Destroy,
},
reader: {
type: 'json',
root: 'data',
},
},
});
然後讓所有類別的項目屬於:
Item.categories().load({
scope: this,
callback: function(aRecords, aOperation, aSuccess) {
Ext.each(aRecords, function(aAssociation) {
// Do something here
}, this);
}
});
然後添加關聯:
var iNewRecord = Item.categories().model.create({ categoryId: '16' });
Item.categories().add(iNewRecord);
+0
這是一個很好的解決方案。我會給出熟悉的答案。 – acteon
1
對於在搜索過程中發現此問題的人,從ExtJS開始5.0,它們支持多到許多關係本身:
http://docs.sencha.com/extjs/5.0.0/apidocs/#!/api/Ext.data.schema.ManyToMany
0
對於ExtJS的6,ManyToMany實現了。
最小實現:
Ext.define('App.models.Group', {
extend: 'Ext.data.Model',
manyToMany: [
'User'
]
});
相關問題
- 1. EXT-JS數據關聯
- 2. 在EXT JS中添加TAB InfoBubble 4
- 3. ManyToMany關聯查詢
- 4. 開發工具Ext-Js 4
- 5. 模擬Ext JS 4文檔
- 6. ASP.NET MVC 4和Ext JS 4 Grid Panel
- 7. 從Ext JS 3.x升級到Ext JS 4 Beta?
- 8. Ext JS 4 ux軟件包在哪裏
- 9. Ext Js 4 gmappanel動態更改中心
- 10. Ext JS中的可重複性4
- 11. 實體框架4 - 關聯
- 12. 的Ext JS 4 - 當您選擇FieldLabel聯合
- 13. Ext JS 4內聯陣列存儲配置
- 14. Symfony Doctrine:刪除ManyToMany關聯
- 15. 在Rails中實現延遲關聯
- 16. 內聯編輯Django中的ManyToMany關係
- 17. Sencha Ext JS 4遇到拖拽時會出現問題
- 18. EXT-js PropertyGrid最佳實踐實現更新?
- 19. Ext Js 4 Grid即時重新配置
- 20. Ext JS上的代理Api錯誤4
- 21. EXT JS 4 MVC揭露問題
- 22. ext js 4:太多的遞歸
- 23. EXT JS中的相關字段
- 24. 實現關聯到MySQL
- 25. 如何實現關聯類?
- 26. 在Ext JS中拖動?
- 27. 在Ext JS中電網
- 28. 使用datepickerplus在Ext JS中
- 29. 實體框架4 - 將現有模型添加到關聯
- 30. 如何在Ext Js 4中從控制器引用多個radiogroup?
我真的不建議你試着用它們的關聯組件來做到這一點,許多人建議你有一個額外的數據存儲到商店之間的關係。我建議你創建自己的商店posts2tags,關聯2個商店,並自己處理過濾器。如果您現在使用它們的關聯組件,您可能已經看到它在每個記錄內部創建了一個存儲。使用它們的關聯組件只會導致您複製數據。 – nscrob