javascript - How to bind data from two tables in PhoneJs? -


i have 2 tables:

  • nom_articole { id(pk), denumire, nom_um_id(fk) }
  • nom_um { id(pk), simbol, denumire }

i want display:

  • nom_articole.id
  • nom_articole.denumire
  • nom_um.simbol

my html code:

<div data-options="dxview : { name: 'nom_articoledetails', title: 'nom_articole' } " > <div  data-options="dxcontent : { targetplaceholder: 'content' } " >     <div data-bind="dxscrollview: { }">         <h2 data-bind="text: nom_articole.denumire"></h2>         <div class="dx-fieldset">             <div class="dx-field">                 <div class="dx-field-label">id</div>                 <div class="dx-field-value" data-bind="text: nom_articole.id"></div>             </div>             <div class="dx-field">                 <div class="dx-field-label">denumire</div>                 <div class="dx-field-value" data-bind="text: nom_articole.denumire"></div>             </div>             <div class="dx-field">                 <div class="dx-field-label">u.m.</div>                 <div class="dx-field-value" data-bind="text: ????????????????"></div>             </div>         </div>         <div data-options="dxcontentplaceholder : { name: 'view-footer', transition: 'none' } " ></div>     </div> </div> 

my javascrip code:

mobileapplication.nom_articoledetails = function(params) { return {     id: params.id,     //nom_um: new mobileapplication.nom_umviewmodel(),     nom_articole: new mobileapplication.nom_articoleviewmodel(),      handledelete: function() {         devexpress.ui.dialog.confirm("are sure want delete item?", "delete item").then($.proxy(function (result) {             if (result)                 this.handleconfirmdelete();         }, this));     },      handleconfirmdelete: function() {         mobileapplication.db.nom_articole.remove(params.id).done(function() {             mobileapplication.app.navigate("nom_articole", { target: "back" });         });     },      viewshown: function() {         nom_articoledetails = this;         mobileapplication.db.nom_articole.bykey(params.id).done(function(data) {             nom_articoledetails.nom_articole.fromjs(data);         });     } }; 

this code generated devexpress multi-channel application wizard.

from information gave, , provided nom_articole , nom_um share same key, code be:

viewshown: function() {     // ... code ...      mobileapplication.db.nom_um.bykey(params.id).done(function(data) {         nom_articoledetails.nom_um.fromjs(data);     }); } 

you uncomment nom_um member , use text: nom_um.simbol binding text in view.

update:

to load object foreign key, have 2 options. first cascading fetches:

mobileapplication.db.nom_articole.bykey(19).done(function (data) {      nom_articoledetails.nom_articole.fromjs(data);       mobileapplication.db.nom_um.bykey(data.nom_um_id).done(function(data) {         nom_articoledetails.nom_um.fromjs(data);     }); });  

the second work if data service configured odata. in case may use expand feature:

mobileapplication.db.nom_articole.bykey(19, { expand: "nom_um" }).done(function (data) {      // data contain nested object });  

p.s. devexpress provides support service, , in case cannot find right answer here, can ask them , share solution.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -