小编Gal*_*len的帖子

KnockoutJS,在ajax调用后更新ViewModel

我正在使用Knockout和Knockout Mapping插件.

  • 我的MVC3 Action直接返回一个View而不是JSON,我将我的Model转换为JSON.
  • 这是一个数据输入表单,由于系统验证的性质,所有这些都在服务层中完成,并在ViewModel中的Response对象中返回警告.
  • 初始绑定和更新正确地处理了导致我出现问题的"更新后"行为.

我的问题是在调用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)

asp.net jquery asp.net-mvc-3 knockout.js

10
推荐指数
1
解决办法
2万
查看次数

价值注入:Dto到域模型(NHibernate)

我正在使用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)

nhibernate dto automapping valueinjecter

6
推荐指数
1
解决办法
2107
查看次数