为什么我的 ExtJS 商店协会不工作 [英] Why isn't my ExtJS Store Association Working

查看:30
本文介绍了为什么我的 ExtJS 商店协会不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题.我想使用不错的 ExtJS 关联,但它们无法正常工作.

I'm having issues. I want to use the nice ExtJS associations, but they're not working properly.

问题:

  • 模型中没有显示关联
  • 加载后没有数据显示

有哪些需要注意的怪癖?

What are the quirks to watch out for?

推荐答案

我最近在 ExtJS 协会中经历了一段非常痛苦的学习曲线,并且遇到了一些有用的文章,以及我自己的问题.这是那些遇到同样痛苦的人的总结.

I recently went through a very painful learning curve with the ExtJS associations, and came across some useful articles, as well as my own gotchas. Here is the summary for those who run into the same pains.

ExtJS 中 HasMany 关联的规则

  • 始终将您的代理放在您的模型中,而不是您的商店中,除非您有很好的理由不 [1]
  • 在以下情况下始终需要您的子模型在 hasMany 关系中使用它们.[2]
  • 如果你想随意加载孩子,总是使用foreignKey
  • 如果您在与父级相同的响应中返回子级,请始终使用 associationKey
  • 如果你愿意,你可以同时使用foreignKey和associationKey
  • 始终将您的 hasMany 关系命名为
  • 始终在您的 hasMany 关系中使用完全限定的模型名称
  • 考虑给读者根一个有意义的名字(除了数据")
  • 子模型不需要belongsTo关系就可以使hasMany工作

[1] store 将继承其模型的代理,您可以随时覆盖它
[2] 为了方便并避免潜在的循环引用,您可以在 app.js 中要求它们

[1] The store will inherit its model's proxy, and you can always override it
[2] To make it easy, and avoid potential circular references, you can require them in app.js

http://extjs-tutorials.blogspot.com/2012/05/extjs-hasmany-relationships-rules.html

ExtJS 中 HasOne 和 BelongsTo 关联的规则

  • 将代理放入模型中,除非您有充分的理由不这样做
  • 始终使用完全限定的模型名称
  • 始终设置 getterName
  • 始终设置 setterName
  • 始终设置associationKey,如果在与此对象相同的响应中返回外部对象
  • 总是设置foreignKey,如果你想随意加载外来对象
  • 考虑将 instanceName 更改为更短的内容
  • getter 的行为取决于是否加载了异物或不.如果已加载,则返回外来对象.除此以外,你需要传入一个回调来获取它.
  • 如果您打算覆盖此关联,则应设置 name 属性.
  • hasMany 的工作不需要belongsTo 关系
  • 如果父模型的id字段不是id",则设置primaryKey属性
  • 有时,您需要为belongsTo 关联使用uses 或requires.手表循环引用虽然.
  • 调用 setter() 函数似乎没有设置实例.设置 object.belongsToInstance = obj if调用 setter().

http://extjs-tutorials.blogspot.com/2012/05/extjs-belongsto-association-rules.html

杂项

  • 如果您要将数据应用到网格,请确保使用新存储在网格上调用 reconfigure()
  • 您的foreignKey"属性作为本地过滤器应用于 ExtJS 存储;如果您看到数据通过网络加载,但是未显示在您的网格中,请确保您的模型具有外键定义为字段的值,否则本地过滤器将排除数据安静.要测试是否是这种情况,请挂入商店的负载"事件并调用 store.clearFilters(),然后查看您的数据是否显示
  • If you're applying your data to a grid, make sure you call reconfigure() on the grid using the new store
  • Your "foreignKey" property will be applied as a local filter to the ExtJS store; if you see the data loading over the network, but not showing in your grid, make sure your model has the foreignKey value defined as a field, or the local filter will exclude the data quiety. To test if this is the case, hook into the store's "load" event and call store.clearFilters(), and see if your data shows up

这篇关于为什么我的 ExtJS 商店协会不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆