2015-11-26 42 views
3

我正在创建聊天室,并且该聊天框是在单击联系人时动态生成的。 在动态生成HTML我有一个文本输入一些文字,这里是HTML绑定在动态生成的HTML中不起作用

<div class="chatboxinput"> 
    <textarea id="chatboxtextareaankur" class="chatboxtextarea" keydown.delegate="checkChatBoxInputKey($event, 'id', 'name')"></textarea> 
</div> 

但“checkChatBoxInputKey”不上的任意键按下事件执行的方法。 请让我知道如何解决这个问题。

回答

3

它不工作,因为Aurelia路上的观点编译器不会有机会编译动态生成的标记找到绑定等

使用if结合添加/删除从DOM元素。这里有一个例子:

http://plnkr.co/edit/kBUz94?p=preview

<template> 
    <button click.delegate="showChatBox = true">Show Chat Box</button> 

    <div if.bind="showChatBox" class="chatboxinput"> 
    <textarea id="chatboxtextareaankur" class="chatboxtextarea" keydown.delegate="checkChatBoxInputKey($event)"></textarea> 
    </div> 
</template> 
export class App { 
    checkChatBoxInputKey(e) { 
    console.log(e.which); 
    return true; 
    } 
} 
+1

日Thnx,它的工作,但应该也有一些机制来手动应用就像我们在淘汰赛怎么做结合。 –