Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Seems like the double ko.applyBindings is causing an issue.</p> <p>This worked:</p> <pre><code>$(function () { var viewModel = { showVoucher: ko.observable(true), voucher: ko.observableArray([ { VoucherNumber: "100000", VoucherImage: "someurl", VoucherExpiry: "20/3/12", VoucherRedeemed: true, VoucherDesc: "ddwqdwqdwqd", VoucherPuchaseDate: "20/12/11", VoucherPrice: "50" }, { VoucherNumber: "200000", VoucherImage: "someurl", VoucherExpiry: "20/3/12", VoucherRedeemed: true, VoucherDesc: "ddwqdwqdwqd", VoucherPuchaseDate: "20/12/11", VoucherPrice: "50" } ]) }; //VIEWMODEL ko.applyBindings(viewModel); }); </code></pre> <p>If there is a better way to write this, please let me know.</p> <p><strong>Edited version below, also trying out mapping:</strong></p> <pre><code>&lt;script&gt; function getVoucherData() { //some ajax call; return data = { "voucher" : [{ VoucherTitle: "Offer title 1", VoucherNumber: "100000", VoucherImage: "someurl", VoucherExpiry: "20/3/12", VoucherRedeemed: true, VoucherDesc: "ddwqdwqdwqd", VoucherPuchaseDate: "20/12/11", VoucherPrice: "50" }, { VoucherTitle: "Offer title 2", VoucherNumber: "200000", VoucherImage: "someurl", VoucherExpiry: "20/3/12", VoucherRedeemed: true, VoucherDesc: "ddwqdwqdwqd", VoucherPuchaseDate: "20/12/11", VoucherPrice: "50" }] }; } function initViewModel() { var viewModel = {}; // PAGE SETUP viewModel.showVoucher = ko.observable(true); viewModel.showMyAccount = ko.observable(false); // GET VOUCHER var voucherData = getVoucherData(); voucherData.voucher.sort(function (left, right) { return left.VoucherNumber &gt; right.VoucherNumber }); viewModel.voucher = ko.mapping.fromJS(voucherData.voucher); // START ko.applyBindings(viewModel); } $(function () { initViewModel(); }); &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload