【发布时间】:2017-07-04 10:34:59
【问题描述】:
我正在使用Kendo Combobox在UI中绑定某些值。是否可以将Array的第一个值设置为默认值?.
【问题讨论】:
-
发布您的代码 sn-p。如何将组合框初始化为选择标记并为其分配值。
标签: angular2-template kendo-combobox
我正在使用Kendo Combobox在UI中绑定某些值。是否可以将Array的第一个值设置为默认值?.
【问题讨论】:
标签: angular2-template kendo-combobox
从组合框的角度来看,您可以使用以下代码添加第一个值作为选择。这与 Angular 代码无关。因为你没有提到任何代码 sn-p 或你想用来实现这一点的功能。
$("#targetComboId").kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: [{
text: "Cotton",
value: "1"
},
{
text: "Polyester",
value: "2"
},
{
text: "Cotton/Polyester",
value: "3"
},
{
text: "Rib Knit",
value: "4"
}
],
index: 0 // Your target value, set it to the index you want
});
这将选择并填充组合框中的第一个值。希望对您有所帮助!
【讨论】:
我知道这对你来说已经晚了,其他人可以使用它。
这是在客户端的 .html 文件中:
<kendo-combobox [data]="SalasType" [valuePrimitive]="true"
[textField]="'name'" (valueChange)="productTypeChange($event)" [valueField]="'id'" [(ngModel)]="selectedValue.id" name="Product Group">
</kendo-combobox>
将此添加到客户端 .ts 文件中: 在公共文件中添加这个(或者你可以在你的 .ts 中创建这个数组)
export const OSSSALELIST = [
{ id: 1, name: 'Product Group' },
{ id: 2, name: 'Product' }
];
在此处调用该全局常量,
SalasType = OSSSALELIST;
selectedValue:any;
在 oninit 方法中:enter code here
this.selectedValue=this.SalasType[0];
【讨论】: