我有两个表:
nom_articole
{ id(PK), denumire, nom_um_id(FK) }nom_um
{ id(PK), simbol, denumire }
我要显示:
- nom_articole.id
- nom_articole.denumire
- nom_um.simbol
我的 html 代码:
<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>
我的 Javascrip 代码:
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 you sure you want to delete this 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);
});
}
};
此代码由 Devexpress 多 channel 应用程序向导生成。
最佳答案
根据您提供的信息,假设 nom_articole
和 nom_um
共享相同的 key ,代码将是:
viewShown: function() {
// ... your code ...
MobileApplication.db.nom_um.byKey(params.id).done(function(data) {
nom_articoleDetails.nom_um.fromJS(data);
});
}
您取消注释 nom_um
成员并使用 text: nom_um.simbol
作为 View 中的绑定(bind)文本。
更新:
要通过外键加载对象,您有两种选择。第一个是级联提取:
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);
});
});
如果您的数据服务已正确配置 OData,则第二个将起作用。在这种情况下,您可以使用展开功能:
MobileApplication.db.nom_articole.byKey(19, { expand: "nom_um" }).done(function (data) {
// data will contain a nested object
});
附言DevExpress 提供 Support 服务,如果您在这里找不到正确的答案,您可以询问他们并分享解决方案。
关于javascript - 如何绑定(bind)PhoneJs中两个表的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700445/