【问题标题】:Databinding issue with MVC4, Breeze and knockoutMVC4、Breeze 和淘汰赛的数据绑定问题
【发布时间】:2012-12-22 05:58:45
【问题描述】:

我是 knockout.js 的新手,使用 MVC4 和 Breez.js 的简单测试页面出现错误。我想将数据绑定到表格。

@{Layout = null;}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width" />
        <title>Breeze Test</title>
        <link rel="stylesheet" href="/Content/breezesample.css" />
    </head>
    <body>
        <header>
            <div class="content-wrapper">
                <div class="float-left">
                    <p class="site-title">
                        <a href="~/">Breeze Test</a>
                    </p>
                </div>
            </div>
        </header>
        <div id="body">
            <section id="content" class="content-wrapper main-content">

                <script type="text/x-jquery-tmpl" id="BookTableTemplate">
                    <table>
                        <thead>
                            <tr>
                                <th>Title</th>
                                <th>Author</th>
                                <th>ISBN</th>
                                <th>Price</th>
                                <th>Read?</th>
                            </tr>
                        </thead>
                        <tbody data-bind="template: {name:'bookRowTemplate', foreach:books}">
                        </tbody>
                    </table>
                </script>

                <script type="text/x-jquery-tmpl" id="bookRowTemplate">
                    <tr>
                        <td>${Title}</td>
                        <td>${Author}</td>
                        <td>${ISBN}</td>
                        <td>${Price}</td>
                        <td>${IsRead}</td>
                    </tr>
                </script>

                <div data-bind="visible: show" style="display: none">
                    <a href="#" data-bind="click: save">Save</a>&nbsp;
                        <input type="checkbox" data-bind="checked: IncludeRead" />
                    include read 

                    <div data-bind="template: 'BookTableTemplate'"></div>
                </div>
                <div id="logmessages"></div>
            </section>
        </div>
        <!--3rd party library scripts -->
        <script src="/Scripts/jquery-1.7.1.min.js"></script>
        <script src="/Scripts/knockout-2.1.0.js"></script>
        <script src="/Scripts/q.js"></script>
        <script src="/Scripts/breeze.debug.js"></script>

        <!-- Application scripts -->
        <script src="/Scripts/app/logger.js"></script>
        <script src="/Scripts/app/bookViewModel.js"></script>
    </body>
</html>

我得到的不是数据输出: ${Title} ${Author} ${ISBN} ${Price} ${IsRead}

【问题讨论】:

  • 我发现我可以这样做:

标签: asp.net-mvc-4 knockout.js breeze


【解决方案1】:

看这个例子:http://knockoutjs.com/documentation/template-binding.html

在您的模板中使用

/>

【讨论】:

    猜你喜欢
    • 2013-10-08
    • 1970-01-01
    • 2014-09-18
    • 2014-04-09
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2013-03-06
    相关资源
    最近更新 更多