Knockoutjs バインディングを使用して、Breezejs の既存のデータ グラフへの更新を保存するのに問題があります。
HotTowel と Durandal を使用した John Papa の SPA から始めました。
症状は、更新が医師の単純なプロパティである場合、更新を医師レコードに保存できることです。ただし、医師に含まれるコレクションの1つに新しい要素を追加すると、コレクション要素を保存できますが、サーバーに送られ、データベースに保存されますが、プロパティはnullで、医師への参照はありません. 例として Specialty を使用していますが、アイテムを追加した Physician レコードのどのコレクションでも同じ動作が見られます。追加された項目は、すべてのプロパティが null でサーバーに送信されます。
医師のグラフはページにうまく表示され、ドロップダウンを適切な特定のフィールドの適切な値に関連付けることができます。チェックボックスなどにも適切な値が表示されます。
私が使用している HTML の一部を次に示します。
<div id="physGraph" class="span10" data-bind="with: currentPhysician()[0]">
<!-- more stuff here -->
<div id="physSpecialties" class="span8">
<span class="span8">Physician Specialties<i class="icon-plus-sign" title="Add new specialty to physician" data-bind="click: $parents[0].addSpecialtyToPhysician"></i></span>
<div class="span8 table-bordered" data-bind="foreach: physicianSpecialties">
<div class="span8">
<span data-bind="text: specialty().name()"></span>
</div>
<div class="span7 table-bordered">
<i class="icon-remove-sign" title="Remove specialty from physician list" data-bind="click: $parents[1].removeSpecialtyFromPhysician"></i>
<select data-bind="options: $parents[1].specialties(), optionsText: 'name', value: specialty()"></select>
</div>
</div>
</div>
<!-- more stuff here -->
</div> <!-- end with: currentPhysician()[0]
私が医師を取得する方法は次のとおりです。
define([services/datacontext', 'viewmodels/physList'], function (datacontext, physListVm) {
var initialized = false;
var physNotes = ko.observableArray();
var currentPhysician = ko.observable();
var vm = {
activate: activate,
title: 'Physician Edit',
currentPhysician: currentPhysician,
addSpecialtyToPhysician: addSpecialtyToPhysician,
save: save,
// more code in here
}
// internal functions for physDetailEdit
function activate() {
initLookups();
var physIdSelectedFromList = physListVm.selectedPhys().id();
return getPhysicianDetail(physIdSelectedFromList);
}
function getPhysicianDetail(requestedPhysId) {
var promise = datacontext.getPhysicianDetails(requestedPhysId, currentPhysician);
return promise;
}
more code in here
}
スペシャリティを追加する方法は次のとおりです。
function addSpecialtyToPhysician(item, event) {
var newItem = datacontext.createSpecialty();
item.physicianSpecialties.push(newItem);
// I've also tried it like this -- > currentPhysician()[0].physicianSpecialties.push(newItem);
}
レコードを保存する方法は次のとおりです。
function save() {
return datacontext.saveChanges();
}
これら 2 つの項目の codeFirst の説明は次のとおりです。
public class Physician
{
public Physician()
{
PhysicianSpecialties = new List<PhysicianSpecialty>();
PhysicianPayers = new List<PhysicianPayer>();
IncentivePrograms = new List<PhysicianIncentiveDetail>();
PhysicianNotes = new List<Note>();
PhysInOrgs = new List<PhysInOrg>();
Memberships = new List<Membership>();
}
public Int32 Id { get; set; }
public Person ContactInfo { get; set; }
public ICollection<Membership> Memberships { get; set; }
public ICollection<PhysicianIncentiveDetail> IncentivePrograms { get; set; }
public ICollection<PhysicianPayer> PhysicianPayers { get; set; }
public ICollection<PhysicianSpecialty> PhysicianSpecialties { get; set; }
public ICollection<Note> PhysicianNotes { get; set; }
public ICollection<PhysInOrg> PhysInOrgs { get; set; }
public string Dea { get; set; }
public string Npi { get; set; }
public string Tin { get; set; }
public string Ssn { get; set; }
public string TaxId { get; set; }
public string MedLicenseNbr { get; set; }
public string MedLicenseState { get; set; }
public DateTime? MedLicenseRecertDate { get; set; }
public EMRSystem EmrSystem { get; set; }
public int ImportBatchId { get; set; }
public bool IsPcp { get; set; }
public bool SoloPractitioner { get; set; }
public bool PartOfHospital { get; set; }
}
public class PhysicianSpecialty
{
public Int32 Id { get; set; }
public Physician Physician { get; set; }
public Specialty Specialty { get; set; }
public bool IsPrimary { get; set; }
}
保存すると得られるものは次のとおりです。
Id IsPrimary Physician_Id Specialty_Id
21 0 NULL NULL
専門分野を Physician グラフに追加することで、Breeze は自動的に医師 ID と、専門分野を currentPhysician()[0] にプッシュしたときにページに表示されるドロップダウンから選択した専門分野を挿入すると想定しています。
誰かが私が見逃しているものを見ることができますか?
ありがとう