Dojox Grid 将两个字段传递给格式化程序
我成功创建了一个 dojox.Grid,但在一种情况下,我需要将两个字段而不是一个字段传递给格式化函数。 例如:
{ field: 'id', name: 'Id', formatter: formatterFunction, },
我需要将“id”和“name”传递给 formatterFunction() 。我该怎么做? 谢谢。
I created a dojox.Grid successfully, but in one case I need to pass two fields to a formatter function instead of just one.
For instance:
{ field: 'id', name: 'Id', formatter: formatterFunction, },
I need to pass to formatterFunction() both 'id' and 'name' for instance. How can I do this?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道 IRC 频道中已经提到过这一点,但我在这里回答是为了让其他人知道,同时也是为了解决您的进一步问题,我不确定是否有人回答过。
这使得您也可以使用格式化程序执行您想要的操作。
http://www.dojotoolkit.org/reference-guide/ dojox/grid/DataGrid.html#usage
在最简单的情况下,无需设置网格的 formatterScope,网格的存储可以通过
this.grid.store
从格式化程序内访问,例如:上述格式化程序的一个非常简单的示例:
http://jsbin.com/upico4/edit
在其中一个测试页面中还有一个这样的示例,它创建一个对象来保存格式化程序并确定格式化程序的范围:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_grid_formatters.html
I know this was already mentioned in the IRC channel, but I'm answering here so others are aware, and also to address your further question that I'm not sure anyone answered.
This makes it possible to do what you want using a formatter as well.
http://www.dojotoolkit.org/reference-guide/dojox/grid/DataGrid.html#usage
In the simplest case, without setting the grid's formatterScope, the grid's store can be accessed from within formatters via
this.grid.store
, e.g.:Here's a really simple example of the above formatter in action:
http://jsbin.com/upico4/edit
There's also an example of this in one of the test pages, which creates an object to hold and scope the formatters:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_grid_formatters.html
从 dojo 1.4 开始,您还可以从商店获取多个字段。应该看起来像这样:
它使用“url”字段中的值来指向您的链接,并且显示的标题填充了商店中“标题”字段中的数据。
As from dojo 1.4 you can also get multiple fields from a store. Should look something like:
That uses the value from the field "url" to point your link at and the displayed title is filled with the data from "Title" field in your store.
您确定要格式化并且可能不使用 get 来代替吗?
当您使用格式化程序时,传递给函数的唯一值是字段表示的值。
但是,如果您要使用 get,则可以使用该项目来访问其他值。 (但是这样你就会失去排序)。
所以对于你的专栏有
然后有
Are you sure that you want to format and maybe not use get instead?
When you use a formatter the only value that is passed to the function is the value that field represents.
However, if you were to use get instead, you could use the item to access the other values. (However then you will lose sorting).
So for your column have
Then have