为什么在淘汰赛js示例中不显示姓氏 [英] Why last name does not show in Knockout js sample
问题描述
我要淘汰新手,并获得如下示例代码
I am knock out newbie and have the sample code like the following
<p>First Name: <strong data-bind="text: firstName" /></p>
<p>Last Name: <strong data-bind="text: lastName" /></p>
<script type="text/javascript">
function AppViewModel() {
this.firstName = "First";
this.lastName = "Last";
}
ko.applyBindings(new AppViewModel());
运行代码时,我看到的只是
When I run the code all I see is
名字:名字 首先
我看不到姓氏,而且名字也重复了两次.我正在使用ASP.Net空项目来创建一个html文件作为默认页面.我正在使用2.0.0版本的淘汰赛. 谢谢.
I do not see the lastname and also the first name repeated twice. I am using ASP.Net empty project to create a html file as the default page. I am using 2.0.0 version of knock out. Thanks.
推荐答案
我会尝试
<p><strong data-bind="text: lastName"></strong></p>
已添加:我刚刚在敲除教程并且有效.
Added I just tried the above in the knockout tutorial and it worked.
何处
<p><strong data-bind="text: lastName"/></p>
没有工作,并且在<strong/>
元素之后破坏了剔除效果. (在Windows chrome浏览器上.)
did not work and broke knockout effects after the <strong/>
element. (On windows chrome browser.)
为什么会出现问题,我认为<strong>
元素并不是最初在dom中创建的,因为它是一个自封闭元素.然后淘汰赛出现,并尝试向其中添加html内容.结果:显示了html,但以某种方式干扰了随后的删除dom更改.
Why the problem I think the <strong>
element was not originally created in the dom because it was a self-closed element. Then knockout came along and tried to add html content to it. Result: the html was displayed, but in a way that interfered with the subsequent knockout dom changes.
无论如何:在多个浏览器上进行测试,不要在通常不期望的情况下使用自动关闭元素.例如<strong/>
In any case: test on multiple browsers and don't use self-closing elements when they aren't normally expected. Eg <strong/>
这篇关于为什么在淘汰赛js示例中不显示姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!