C# 无法使淘汰模板在现有页面中工作
我有一个简单的敲除模板,但因为它在一个使用敲除的现有页面中,我无法让我的模板工作。我没有在页面上看到你好。任何建议都可以接受!谢谢 代码片段C# 无法使淘汰模板在现有页面中工作,c#,asp.net,asp.net-mvc,asp.net-mvc-4,knockout.js,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Knockout.js,我有一个简单的敲除模板,但因为它在一个使用敲除的现有页面中,我无法让我的模板工作。我没有在页面上看到你好。任何建议都可以接受!谢谢 代码片段 <script type="text/html" id="childtag-template"> <ul data-bind="template: { name: 'tag-template'}"></ul> <div data-bind="template: { name: 'keyword-te
<script type="text/html" id="childtag-template">
<ul data-bind="template: { name: 'tag-template'}"></ul>
<div data-bind="template: { name: 'keyword-template'}"></div> <!-- new bit -->
</script>
当我可以成功加载模板时,我只需要一个简单的表单,它直接从淘汰示例中获取,允许添加和删除列表。我让它独立工作,但当将标记和js放入现有文件时,我会得到js错误
更新
我添加了以下更改(请参见viewModel.Keywords)。Firefox没有报告任何错误,但我没有在页面上看到我的hello
window.Helper = {
Start: function (x) {
var viewModel = Helper.XViewModel(x);
window.ArticleManagerHelper.ViewModel = viewModel;
ko.applyBindings(viewModel);
viewModel.Keywords = ko.observable(); // new line of code
我已将以下内容添加到模板中
<input type="text" data-bind="value: Keywords"/>
好的,下面是我为让它工作所做的 请注意,我使用了json的简化版本,因此我可以创建一个工作的JSFIDLE,但概念仍然相同
<!--html -->
<div data-bind="template: { name: 'keyword-template', data: Article }"></div>
<!-- template -->
<script type="text/html" id="keyword-template">
<input type="text" data-bind="value: Keywords"/>
</script>
data:Article
你能详细说明你遇到了什么JS错误吗?我现在没有收到任何错误,尽管我仍然无法看到我的messagewindow.helper.Start应该是window.helper.Start在你的情况下…哈哈…我杀了我。你能发布序列化时的视图模型吗?所以我可以创建一个提琴。我可以在哪里临时发布一个长字符串?谢谢,我已经做了更改,但是我得到了与以前相同的响应??(即“hello”不会出现在页面上)window.helper.Start应该是window.helper.Start在您的“case”中…哈哈…我杀了我…两次!更新了更多信息,请尝试此选项。:)谢谢,但我在页面上也没有得到任何东西:(我的模板只是在我的hijames中有“hello”,在简化的jsFiddle中工作。请查看我的更新答案。)
window.Helper = {
Start: function (x) {
var viewModel = Helper.XViewModel(x);
window.ArticleManagerHelper.ViewModel = viewModel;
ko.applyBindings(viewModel);
viewModel.Keywords = ko.observable(); // new line of code
<input type="text" data-bind="value: Keywords"/>
<!--html -->
<div data-bind="template: { name: 'keyword-template', data: Article }"></div>
<!-- template -->
<script type="text/html" id="keyword-template">
<input type="text" data-bind="value: Keywords"/>
</script>