且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

敲除可拖动可分类映射克隆改变.

更新时间:2023-02-09 12:24:31

您希望映射选项看起来像这样:

You would want your mapping options to look something like:

var options = {
    productArray: {
        create: function(mappingData) {
            var result = ko.mapping.fromJS(mappingData.data);

            result.clone = function() {
                return { productID: result.productID() };
            };

            return result;
        }
    }
};

或者,您可以为产品创建带有克隆函数的构造函数,然后像return new Product(mappingData.data);

Alternatively, you could create a constructor for your product with a clone function on it and just return that like return new Product(mappingData.data);

我上面的克隆只是将productID返回为不可观察的值,除非您需要对该值的变化做出反应,否则应该没问题.

I had the clone above just return the productID as a non-observable, which should be fine unless you need to react to that value changing.

calculatedName函数的第一行将需要像这样:

The first line of your calculatedName function would then need to be something like:

var x = ko.unwrap(arg.productID);

var x = ko.unwrap(arg.productID);

这将检索该值是否可见,以便该函数可以对productArray或listArray使用.

This will retrieve the value whether it is observable or not, so the function can work against the productArray or the listArray.

http://jsfiddle.net/rniemeyer/hLqctg4L/