Knockout isDirty示例,使用映射插件中的动态viewmodule [英] Knockout isDirty example, using dynamic viewmodule from mapping plugin

查看:74
本文介绍了Knockout isDirty示例,使用映射插件中的动态viewmodule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Ryan Niemeyer的肮脏旗帜. 在 jsFiddle 中可以看到他的方法的一个例子.

I'm using Ryan Niemeyer's Dirty Flag. An example of his method can be seen in this jsFiddle.

他在ViewModel上有一个dirtyItems方法

He has a dirtyItems method on the ViewModel

this.dirtyItems = ko.computed(function() {
  return ko.utils.arrayFilter(this.items(), function(item) {
    return item.dirtyFlag.isDirty();
  });
}, this);

但是,我似乎无法让他的dirtyItems方法处理我的数据.最大的不同是我正在使用映射插件. 我尝试过的一切都变空了.

However, I can't seem to get his dirtyItems method working with my data.The biggest difference is that I am using the mapping plugin. Everything I have tried comes back empty.

这是我的实现的 jsFiddle .

推荐答案

您可以将dirtyFlag添加到ProfilePropertyValue中,例如:

You could add the dirtyFlag to the ProfilePropertyValue like:

var mappingOptions = {
    ProfilePropertyValue: {
        create: function (mappingoptions) {
            var data = mappingoptions.data;
            data.ProfilePropertyValue = data.ProfilePropertyValue || {
                "ID": null,
                    "Checkbox": ko.observable(false)
            };

            var result = ko.mapping.fromJS(data);
            result.dirtyFlag = ko.dirtyFlag(result);

            return result;
        }
    }
};

然后,如果需要,则在构建脏物品列表时需要对其进行检查.

Then, you would need to check it when building your list of dirty items, if that is something that you need.

示例: http://jsfiddle.net/rniemeyer/7DGfs/

这篇关于Knockout isDirty示例,使用映射插件中的动态viewmodule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆