使用knockout.js 完畢template binding

來源:互聯網
上載者:User

標籤:blog   mvc   span   ring   oca   lsp   ret   使用   move   

//1.template <script id="txn-details-template" type="text/html">    <!--Status 0 : Success , Status 1 : Processing , Status 2 : Rejected-->    <div class="pull-left last-ten-records">        @string.Format(Resx.RecentRecordsShowHere_0,5)    </div>    <div class="row">        <table class="table table-bordered tbl">            <thead>                <tr>                    <th>                        @Resx.WithdrawalHistory_RequestDate                    </th>                    <th>                        @Resx.WithdrawalHistory_TransactionNo                    </th>                    <th>                        @Resx.WithdrawalHistory_Method                    </th>                    <th>                        @Resx.WithdrawalHistory_Status                    </th>                    <th>                        @Resx.WithdrawalHistory_Amount                    </th>                </tr>            </thead>            <tbody data-bind="foreach: Values">                <tr>                    <td data-bind="text: Date"></td>                    <td data-bind="text: TransactionNo"></td>                    <td data-bind="text: Method"></td>                    <!-- ko if: StatusCode == 0 -->                    <td style="color:#efc944" data-bind="text: Status"></td>                    <!-- /ko -->                    <!-- ko if: StatusCode == 1 -->                    <td style="color:#efc944" data-bind="text: Status"></td>                    <!-- /ko -->                    <!-- ko if: StatusCode == 2 -->                    <td style="color:#80ca0b" data-bind="text: Status"></td>                    <!-- /ko -->                    <!-- ko if: StatusCode == 3 -->                    <td style="color:#ff7d00" data-bind="text: Status"></td>                    <!-- /ko -->                    <!-- ko if: StatusCode == 4 -->                    <td style="color:#ff7d00" data-bind="text: Status"></td>                    <!-- /ko -->                    <td><span data-bind="text: Amount" style="float: right;margin-right: 27%;"></span></td>                </tr>            </tbody>            <tfoot>                <tr><td colspan="5"></td></tr>            </tfoot>        </table>    </div></script>//2.div for binding<div id="txn-details" class="txn-details" data-bind="template: { name: ‘txn-details-template‘ }">        </div>

//3.js var preFetch = {    pageLoaded: false, data: undefined};$(document).ready(function () {    $("#btnAccountDetails").click(function () {        var arrow = $("#arrow");        if ($(arrow).attr("showing")) {            $(arrow).html("<i class=\"fa fa-angle-double-up\"></i>");            $(arrow).removeAttr("showing", 1);            $("#txn-details").slideToggle(false);            prefetchDataToCache();            return;        }        $(arrow).html("<i class=\"fa fa-angle-double-down\"></i>");        $(arrow).attr("showing", 1);        $("#txn-details").slideToggle(true);    });    prefetchDataToCache();});function binding() {    var vmVals = ko.observableArray();    for (var i = 0; i < preFetch.data.Values.length; i++) {        vmVals.push(preFetch.data.Values[i]);    }    ko.applyBindings({ Values: vmVals }, document.getElementById("txn-details"));}function prefetchDataToCache() {    $.ajax({        type: ‘POST‘,        url: $("#hdnLatestTxnUrl").val(),        success: function (data) {            preFetch.data = data;            ko.cleanNode($("#txn-details")[0]);            binding();        }    });}


MVC Controller 返回的json結構:


{Values : [{Status : ‘xxx‘ ,StatusCode : 1 , Date: ‘xxxx‘, TransactionNo : ‘xxxx‘ , Method: ‘xxx‘ , Amout : 100} ]}


使用knockout.js 完畢template binding

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.