给定一个包含多个字段的页面部分的模型,并使用如下数据填充:
{
"fields": [
{
"id": 1,
"type": "text",
"caption": "Name",
"value": "Bob"
},
{
"id": 2,
"type": "bool",
"caption": "Over 24?",
"value": 0
},
{
"id": 3,
"type": "options",
"options" : [ "M", "F"],
"caption": "Gender",
"value": "M"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想有一个通用的部分组件,它不知道它可能包装的不同类型的字段,以避免部分模板中的大量条件逻辑,并通过放入自我来添加新的字段类型视图/组件包含文件,而不必修改单独的组件.
我的理想是,Component的选择器足够具体,我可以通过基于绑定到模型的属性值在父Component的模板中选择一个元素来实现这一点.例如:(原谅任何语法问题,因为我在SO窗口中对此进行了编码,要注意的主要部分是BooleanComponent.ts上的选择器
SectionComponent.ts
@Component({
selector: 'my-app'
})
@View({
template: `
<section>
<div *ng-for="#field of fields">
<field type="{{field.type}}"></field>
</div>
</section>
`,
directives: [NgFor]
})
class SectionComponent {
fields: Array<field>;
constructor() {
this.fields = // retrieve section fields via service …Run Code Online (Sandbox Code Playgroud) 我有一个带有可排序列的 WPF DataGrid。我不想在任何特定列上预先排序网格。我只希望用户第一次单击列标题时的默认排序方向是降序而不是升序。
更改排序列时,CollectionViewSource 上的 SortDescription.Direction 和 by DataGridTextColumns 的 SortDirection 属性都不会影响默认排序方向。它总是在第一次单击列标题时选择升序。
99% 的时间都需要降序,用户工作流中的列切换是频繁的,因此这增加了很多不必要的点击。如果有 XAML 解决方案,我非常喜欢 XAML 解决方案,但如有必要,我会在事件上使用代码技巧。