为什么姓氏不显示在 Knockout js 示例中
我是新手,并且有如下示例代码
<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());
当我运行代码时,我看到的只是
FirstName: First 首先,
我没有看到姓氏和名字重复两次。我正在使用 ASP.Net 空项目创建一个 html 文件作为默认页面。我使用的是2.0.0版本的knock out。 谢谢。
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
FirstName: First
First
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试
添加我刚刚在knockout教程<中尝试了上述内容< /a> 成功了。
然而
在
元素之后不起作用并破坏了淘汰效果。 (在 Windows chrome 浏览器上。)
为什么会出现问题 我认为
元素最初并不是在 dom 中创建的,因为它是一个自封闭元素。然后knockout出现并尝试向其中添加html内容。结果:html 被显示了,但是以某种方式干扰了后续的淘汰 dom 更改。
无论如何:在多个浏览器上进行测试,并且在通常不需要的情况下不要使用自关闭元素。例如
I'd try
Added I just tried the above in the knockout tutorial and it worked.
Whereas
did not work and broke knockout effects after the
<strong/>
element. (On windows chrome browser.)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.In any case: test on multiple browsers and don't use self-closing elements when they aren't normally expected. Eg
<strong/>