且构网

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

如何从Knockoutjs中排除某些属性toJS()

更新时间:2023-09-08 23:19:28

您是否尝试过 ignore 关键字?它与include的用法类似:

Have you tried the ignore keyword? It has a similar usage to the include:

var mapping = {
    'ignore': ["propertyToIgnore", "alsoIgnoreThis"]
}
var viewModel = ko.mapping.toJS(data, mapping);

您可以在执行服务器数据的原始映射时使用ignore,然后它不会当你把它转换回JS时,完全依赖你的对象。

You could just use ignore when you do the original mapping of the server data, then it won't be on your object at all when you convert it back to JS.