【问题标题】:Binded list is not showing in html view source in knockout.js?绑定列表未显示在 knockout.js 的 html 视图源中?
【发布时间】:2017-02-06 07:48:57
【问题描述】:

我正在使用knockout js来绑定我表中的链接列表这里是代码

  <table class="table table-bordered">
            <thead>
                <tr>
                    <th style="width:10%;">#</th>
                    <th style="width:50%;">Link</th>
                    <th style="width:20%;">Active</th>
                    <th style="width:20%;">Action</th>
                </tr>
            </thead>
            **<tbody data-bind="foreach:LinkList">**
                <tr>
                    <td data-bind="text:$index()+1"></td>
                    <td><span data-bind="text:$data.LinkName.length <= 40 ? $data.LinkName : $data.LinkName.substring(0, 40) + '...'"></span></td>
                    <td>
                        <input type="checkbox"  data-bind="checked:$data.IsActive" disabled />
                    </td>
                    <td>
                        <button class="btn btn-xs btn-primary" type="button" title="Edit"
                                data-bind="click:$parent.OnClickEditBtn">
                            <span class="glyphicon glyphicon-edit"></span>
                        </button>
                        <button class="btn btn-xs btn-danger" type="button" title="Delete"
                                data-bind="click:$parent.OnClickDeleteBtn">
                            <span class="glyphicon glyphicon-trash"></span>
                        </button>
                    </td>
                </tr>
            </tbody>
        </table>

这里我使用了foreach来绑定链接列表以显示在HTML页面上 我还附上了该页面的链接 http://growingtab.com/links

但是当您检查页面源代码中的 html 页面时,链接没有显示在其源代码中? 那么我怎样才能在页面源中显示这些链接呢? 有什么办法可以显示吗?

【问题讨论】:

  • 请帮忙还是没有任何反应
  • 你能分享你的视图模型吗?
  • 我认为没有办法做到这一点。源头就是源头。为什么首先需要它们出现在源代码中?如果您只需要访问者能够看到他们的代码,您可能可以在呈现页面的另一个部分中显示链接。

标签: javascript jquery html knockout.js rendering


【解决方案1】:

显示的源代码是服务器在请求页面时为客户端返回的任何内容——您实际上是在进行不会修改原始源的 DOM 操作。您可以使用 Firebug 等开发工具检查 DOM 的当前状态,或者将逻辑移至服务器端,服务器端将返回生成的 HTML。

jQuery DOM changes not appearing in view source

createElement() not showing up in view source

【讨论】:

  • 是的,我必须在其中传递我的模型类来实现服务器端代码,现在已经完成了,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-23
  • 2014-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-01
相关资源
最近更新 更多