2016-09-19 89 views
-1

Nativescript應用程序:我正在創建Dinamy TextFields。沒有ngModel&textfield閃爍的OnBlur事件

1)問題 - 當我點擊dinamicly生成的文本字段時,鍵盤顯示爲毫秒和消失。當我點擊非常快的幾次然後鍵盤停留。

2)如何在動態生成的TextField上進行onChange/onBlur事件?就像當我更新textField時,我需要調用一個方法。

這是當前的列表: (模糊)不工作: <StackLayout col="1" row="0"> <ListView [items]="categoryService.attributes | async"> <template let-item="item" let-i="index"> <GridLayout rows="50 100"> <Label [text]="item.name"></Label> <TextField #input *ngIf="item.type=='text'" row="1" hint="Enter Value here" [text]="item.name" (blur)="categoryService.onAttributeChange(item, item.type, null, input.value)"></ TextField> <Switch #switch *ngIf="item.type=='checkbox'" row="1" checked="false" (checkedChange)="categoryService.onAttributeChange(item, item.type, null, switch.checked)"></Switch> <DropDown #aa *ngIf="item.type=='select'" row="1" [items]="categoryService.showAttributeValues(item.value)" [selectedIndex]="selectedIndex" (selectedIndexChange)="categoryService.onAttributeChange(item, item.type, aa.selectedIndex)"></DropDown> </GridLayout> </template> </ListView> </StackLayout>

謝謝!

+0

HI IvRRimUm,與顯示的'TextField'鍵盤的問題s在ListView中已經被修復,並將在NS 2.4中可用 - 問題https://github.com/NativeScript/NativeScript/issues/2942 –

回答

0

關於第二個問題,您可以使用textChange方法並返回$event作爲參數,這將有助於您單獨獲取每個TextField的文本。您可以查看下面的示例代碼。關於顯示鍵盤的問題,它可能與listview itemTap事件有關。然而,這個問題已經在Android上重現,並且仍在尋找可能的解決方案。

app.component.html

<StackLayout> 
    <ListView [items]="myItems" (itemTap)="onItemTap($event)"> 
     <template let-item="item" let-i="index" let-odd="odd" let-even="even"> 
      <StackLayout [class.odd]="odd" [class.even]="even"> 
       <Label [text]='"index: " + i'></Label> 
       <Label [text]='"[" + item.id +"] " + item.name'></Label> 
       <TextField (tap)="onTap($event)" hint="Enter text" text="" (textChange)="ontextChange($event)"></TextField> 

      </StackLayout> 
     </template> 
    </ListView> 
</StackLayout> 

app.component.ts

import {Component, Input, ChangeDetectionStrategy} from '@angular/core'; 
import {TextField} from "ui/text-field"; 
import app = require("application"); 

class DataItem { 
    constructor(public id: number, public name: string) { } 
} 

@Component({ 
    selector: "my-app", 
    templateUrl: "app.component.html", 
}) 
export class AppComponent { 
    public myItems: Array<DataItem>; 
    private counter: number; 
    public status =true; 

    constructor() { 
     this.myItems = []; 
     this.counter = 0; 
     for (var i = 0; i < 50; i++) { 
      this.myItems.push(new DataItem(i, "data item " + i)); 
      this.counter = i; 
     } 
    } 

    public onItemTap(args) { 
     console.log("------------------------ ItemTapped: " + args.index); 
    } 

    public ontextChange(args){ 
     console.log("text "+args.object.text); 
    } 
} 

我希望這有助於