knockout.js - Breeze Project - Null Fields Removed -


if run breeze projection query:

var item; breeze.entityquery .from("sometable") .where("id", "==", id) .select("a, b, c, d") .using(myentitymanager).execute() .then(function(data) { item = ko.observable(data.results[0]); }); 

and row in table, b , c null, i'll object without b , c.

{ a: "somevalue", b: "someothervalue" } 

in ui have:

<div data-bind="with: item"> <span data-bind="text: a" /> <span data-bind="text: b" /> <span data-bind="text: c" /> <span data-bind="text: d" /> </div> 

i error -

referenceerror: unable process binding "with: function(){return item}" message: unable process binding "text: function(){return b}" message: 'b' undefined

am missing something? how can b , c in results, value of null?

here situation, modeled after northwind sample database available interactive testing @ http://learn.breezejs.com/

var myentitymanager = new breeze.entitymanager('api/northwind');  function employee() {     this.firstname = ko.observable(null);     this.lastname = ko.observable(null); } employee.prototype.init = function (data) {     if (data) {         this.firstname(data.firstname);         this.lastname(data.lastname);     } else {         this.firstname(null);         this.lastname(null);     } }; employee.prototype.loadfromid = function (id) {     var self = this;     breeze.entityquery.from("employees")     .where("employeeid", "==", id)     .select("firstname, lastname")     .using(myentitymanager).execute()     .then(function (data) {         self.init(data.results[0]);     })     .fail(function () {         self.init(null);         // show or log error message     }); }; 

usage:

var viewmodel = new employee(); viewmodel.loadfromid(1);  ko.applybindings(viewmodel); 

the key point need actual view model first. not writing breeze code, writing knockout code, breeze being means of filling viewmodels data.

so if view requires properties a, b, c , d, need create viewmodel first provides them. make sure views work empty view models. after can turn task of filling them data.


Comments

Popular posts from this blog

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -