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

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

问题描述

我有问题。我想使用很好的ExtJS关联,但是它们不能正常工作。



问题:




  • 在模型中没有关联

  • 加载后没有显示数据



<

解决方案

我最近经历了一个非常痛苦的学习曲线与ExtJS协会,并发现了一些有用的文章,以及我自己的问题。



ExtJS中hasMany关联规则




  • 总是把你的代理商放在你的模型,而不是你的商店,除非你
    有一个非常好的理由不要[1]

  • 如果
    在有多个关系中使用它们,请始终要求您的子模型。 [2]

  • 如果您想随意加载孩子,请始终使用foreignKey

  • 如果您将相同的回复中的孩子返回,请始终使用associationKey父母

  • 如果您喜欢,可以同时使用foreignKey和associationKey

  • 始终命名您的hasMany关系

  • 始终使用hasMany关系中的全限定型号名称

  • 考虑给读者一个有意义的名称(数据除外)

  • 子模型不需要hasTo的关系forMany工作



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



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



ExtNS中的HasOne和属性协会规则




  • 将代理置于模型中,除非您有非常好的理由不要

  • 始终使用全限定型号名称

  • 始终设置getterName

  • 始终设置setterName

  • 如果外部对象在与此对象相同的响应中返回,则始终设置关联关键字

  • 如果要随意加载异物,请始终设置foreignKey

  • 考虑将instanceName更改为更短的

  • 吸气剂的行为方式取决于异物是否加载
    。如果加载,则返回异物。否则,
    你需要传递一个回调才能得到它。

  • 如果您打算覆盖此关联,则应设置name属性。

  • 您不需要hasMany工作的belongsTo关系

  • 如果父模型的id字段不是id,则设置primaryKey属性

  • 有时您需要使用或需要belongsTo关联。观看
    出来用于循环引用。

  • 调用setter()函数
    似乎没有设置实例。设置object.belongsToInstance = obj如果
    调用setter()。



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



其他




  • 如果您将数据应用到网格,请确保使用新的商店调用网格上的reconfigure()。

  • 您的外键属性作为本地过滤器应用于ExtJS存储;如果您看到通过网络加载数据,但
    未显示在您的网格中,请确保您的模型具有定义为字段的foreignKey
    值,否则本地过滤器将排除数据
    quiety。要测试是否是这种情况,请钩入商店的加载
    事件并调用store.clearFilters(),并查看您的数据是否显示


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

Issues:

  • no association showing in the model
  • no data showing up after load

What are the quirks to watch out for?

解决方案

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.

Rules for HasMany Associations in ExtJS

  • Always put your Proxies in your Models, not your Stores, unless you have a very good reason not to [1]
  • Always require your child models if using them in hasMany relationships. [2]
  • Always use foreignKey if you want to load the children at will
  • Always use associationKey if you return the children in the same response as the parent
  • You can use both foreignKey and associationKey if you like
  • Always name your hasMany relationships
  • Always use fully qualified model names in your hasMany relationship
  • Consider giving the reader root a meaningful name (other than "data")
  • The child model does not need a belongsTo relationship for the hasMany to work

[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

Rules for HasOne and BelongsTo Associations in ExtJS

  • Put the proxy in the model, unless you have a very good reason not to
  • Always use fully qualified model name
  • Always set the getterName
  • Always set the setterName
  • Always set the associationKey, if the foreign object is returned in the same response as this object
  • Always set the foreignKey, if you want to load the foreign object at will
  • Consider changing the instanceName to something shorter
  • The getter behaves differently depending on whether the foreign object is loaded or not. If it's loaded, the foreign object is returned. Otherwise, you need to pass in a callback to get it.
  • You should set the name property if you plan to override this association.
  • You do not need a belongsTo relationship for a hasMany to work
  • Set the primaryKey property if the id field of the parent model is not "id"
  • Sometimes you need to use uses or requires for the belongsTo association. Watch out for circular references though.
  • Calling setter() function does not seem to set the instance. Set object.belongsToInstance = obj if calling the setter().

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

Misc

  • 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天全站免登陆