Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks, Paul. I was up late last night. I forgot to reply to add the answer. I got an answer from Rob Eisenberg, the creator of Durandal. My mistake was that I needed to return the promise from the .getJSON() call. I also needed to add another function, viewAttached(), to the module for all of my jQuery calls that refer to an element in the DOM.</p> <p>Here is Rob's reply to <a href="https://groups.google.com/forum/#!topic/durandaljs/_x78N1KGlpc">Help with observableArray not updating in view</a>. They are really helpful in this group. Rob is pretty quick to answer most questions.</p> <p>Below is the corrected code for the viewmodel:</p> <pre><code>define(function(require){ // Load System for debugging var system = require('durandal/system'); // Customer Structure function Customer(data) { this.name = ko.observable(data.name); this.dob = ko.observable(data.dob.substring(5,7) + '/' + data.dob.substring(8,10) + '/' + data.dob.substring(0,4)); this.phone = ko.observable(data.phone); this.email = ko.observable(data.email); }; // Form observables var inputName = ko.observable(''); var inputDOB = ko.observable(''); var inputPhone = ko.observable(''); var inputEmail = ko.observable(''); // Customers array var customers = ko.observableArray([]); return { inputName: inputName, inputDOB: inputDOB, inputPhone: inputPhone, inputEmail: inputEmail, customers: customers, // This allows us to add jQuery as usual viewAttached: function() { // Change the selected nav item $('.customerNav').addClass('active'); $('.firstNav').removeClass('active'); $('.secondNav').removeClass('active'); $('.date').datepicker(); }, // This performs any needed functionality after the page loads activate: function(data) { // Capture the module instance var self = this; // Get current customers from database and add to customers observableArray var promise = $.getJSON( // Backend script 'php/query.php', // Variables sent to query.php { mode: 'select', table: 'customers', 'fields[]': '*', 'values[]': '*' }, // Callback function function(data) { var customer = $.map(data, function(item) {return new Customer(item) }); system.log(customers); self.customers(customer); } ); return promise; } }; }); // define </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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