Visualforce 中的 sObject?
我有一个顶点控制器,它构建一个要在数据表中显示的列表。该列表组合了不同的对象,因此我创建的变量是一个列表,
假设该列表中的所有对象都有一个“external__c”字段。我如何告诉 Visualforce 渲染这个字段?使用 {!obj.external__c} 将不起作用,因为它是 sObject。
I have an apex controller which builds up a list to be displayed in a datatable. The list combines different object, so the variable I create is a List
Say all the objects in this list have an "external__c" field. How do I tell the visualforce to render this field? Using {!obj.external__c} will not work since it is an sObject.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有 SObject 列表,则可以使用 obj.get('external__c') 获取公共字段,但通常必须将结果转换为能够使用它的类型。
您可以在代码中创建一个自定义类,您可以在其中填充各种对象:
不能 100% 确定我的 getter 语法是否正确,但它很接近;)希望这将帮助您实现您所追求的目标!
If you've got a list of SObjects you can get a common field using
obj.get('external__c')
though you generally have to cast the result to a type to be able to use it.You can create a custom class in code which you can fill with various objects:
Not 100% sure if my syntax on the getter is correct, but it's close ;) Hopefully this will help you achieve what you're after!
假设列表属性在控制器中像这样声明:
Public List; ColdOnes { 得到;放; }
。在 Visualforce 中,您可以通过控制器中的属性名称引用啤酒...{!ColdOnes}
。以下内容大部分取自 Visualforce 指南,但我对其进行了调整以适应我们的 thist 淬灭主题:)请注意,如果您在代码中使用查询值设置 ColdOnes,则需要选择您想要的字段输出到您的 Visualforce 中。所以:
好吧,我要去喝一品脱。希望有帮助!
Let's say the list property is declared like so in your controller:
Public List<Beer__c> ColdOnes { get; set; }
. Well in Visualforce, you reference the beers by their property name in the controller...{!ColdOnes}
. The following is mostly taken from the Visualforce guide, but I have adapted it to suit our thist-quenching subject matter :)Just be aware that if you are setting ColdOnes with a queried value in your code, you need to select the fields you intend to output in your Visualforce. So:
Well, I'm off for a pint. Hope that helps!