我正在使用Knockout和Knockout Mapping插件.
我的问题是在调用AJAX POST并且接收我的JSON响应后,敲除不会更新我的所有绑定...就像observable/mappings已经下降一样
如果我包含一个额外的ko.applyBindings(viewModel); 在成功的事情确实有效...然而问题出现多个绑定,并确定这不是正确的解决方案.
这是HTML/Template/Bindings
<!-- Start Form -->
<form action="@Url.Action("Edit")" data-bind="submit: save">
<div id="editListing" data-bind="template: 'editListingTemplate'"></div>
<div id="saveListing" class="end-actions">
<button type="submit">Save Listings</button>
</div>
</form>
<!-- End Form -->
<!-- Templates -->
<script type="text/html" id="editListingTemplate">
<div class="warning message error" data-bind="visible: Response.HasWarning">
<span>Correct the Following to Save</span>
<ul>
{{each(i, warning) Response.BusinessWarnings}}
<li data-bind="text: Message"></li>
{{/each}}
</ul>
</div>
<fieldset>
<legend>Key Information</legend>
<div class="editor-label">
<label>Project Name</label>
</div>
<div class="editor-field">
<input data-bind="value: Project_Name" class="title" />
</div> …Run Code Online (Sandbox Code Playgroud) 我正在使用ValueInjecter将属性从域模型映射到通过服务层提供的DTO.有问题的服务也接受更新...因此传入更新的DTO,然后将其注入域对象并保存.
// Domain
public class Member
{
public Country Country { get; set; }
}
public class Country
{
public string Code { get; set; }
public string Name { get; set; }
}
//Dto
public class MemberDto
{
public string CountryCode { get; set; }
}
//Transformation Method attempt 1
public Member InjectFromDto (MemberDto dto, Member source)
{
source = source.InjectFrom<UnflatLoopValueInjection>(dto);
return source;
}
Run Code Online (Sandbox Code Playgroud)
现在所有上面的代码都更新了Property Member.Country.Code,这显然不是我需要它做的.
所以从文档中,我想我需要创建一个覆盖并得到这个:
public class CountryLookup: UnflatLoopValueInjection<string, Country>
{
protected override Country SetValue(string …Run Code Online (Sandbox Code Playgroud)