首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从其他控件中选择kendo-combobox的项目

从其他控件中选择kendo-combobox的项目
EN

Stack Overflow用户
提问于 2018-01-17 20:02:24
回答 1查看 203关注 0票数 0

我有一台kendo-combobox。当焦点位于kendo-combobox时为Keyboard navigation works very well

ButI希望通过放置在kendo-combobox附近的按钮选择下一个可用项目。让我展示一下我的代码:

HTML:

代码语言:javascript
复制
<p>Favorite sport:</p>  
<kendo-combobox [data]="listItems" [allowCustom]="true" #superComboBox>
</kendo-combobox>

<button (click)="selectUpperItem()">
    Up
</button>
<button (click)="selectLowerItem()">
    Down
</button>

JavaScript

代码语言:javascript
复制
public listItems: Array<string> = 
[
   "Baseball", "Basketball", "Cricket", "Field Hockey", "Football", "Table Tennis", 
   "Tennis", "Volleyball"
];

selectUpperItem(){
   //pseudocode: this.superComboBox.nextUpperItem();    
   //How can I accomplish this?
}

selectLowerItem(){
   //pseudocode: this.superComboBox.nextLowerItem();    
   //How can I accomplish this?
}

控件如下所示:

因此,例如,当我单击Up按钮时,下一个可用项应该在kendo-combobox处被选中。

是否可以通过放置在kendo-combobox附近的按钮选择下一个可用项目

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-17 22:35:07

如果您正在尝试使用Up/Down按钮选择选项,您可以执行类似以下操作。

使用[(ngModel)]跟踪当前选择:

代码语言:javascript
复制
<kendo-combobox 
    [data]="listItems" 
    [allowCustom]="allowCustom" 
    [(ngModel)]="currentSelection">
</kendo-combobox>

然后在您的.ts中检查currentSelection是否为undefined,并相应地操作选择/索引:

代码语言:javascript
复制
private string: currentSelection;
private number: currentIndex;

private selectUpperItem() {
  if (this.currentSelection == undefined) {
    this.currentSelection = this.listItems[this.listItems.length - 1];
    this.currentIndex = this.listItems.length - 1;
  } else {
    this.currentIndex = this.listItems.indexOf(this.currentSelection);
    this.currentSelection = this.listItems[this.currentIndex - 1];
  }
}

private selectLowerItem() {
  if (this.currentSelection == undefined) {
    this.currentSelection = this.listItems[0];
    this.currentIndex = 0;
  } else {
    this.currentIndex = this.listItems.indexOf(this.currentSelection);
    this.currentSelection = this.listItems[this.currentIndex + 1];
  }
}

它的设置是,如果按undefined和click Up将选择最后一个选项,而当单击undefined和Down时将选择第一个选项。

检查此plunker

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48300713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档