使用require.js的Knockout.js映射插件 [英] Knockout.js mapping plugin with require.js

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

问题描述

在require.js中加载映射插件的标准方法是什么?

What is the standard way of loading mapping plugin in require.js ?

下面是我的config.js(require.js配置文件)

Below is my config.js (require.js config file)

require.config({
    // Initialize the application with the main application file.
    deps: ["app"],

    paths:{
        // JavaScript folders.
        libs: "lib",
        plugins: "lib/plugin",
        templates: "../templates",

        // Libraries.
        jquery: "lib/jquery-1.7.2.min",
        underscore: "lib/lodash",
        text: 'text',
        order: 'order',
        knockout: "lib/knockout",
        knockoutmapping: "lib/plugin/knockout-mapping"

    },

    shim:{
        underscore:{
            exports: '_'
        },

        knockout:{
            deps: ["jquery"],
            exports: "knockout"
        }
    }
}

在我的视图模型中

define(['knockout', 'knockoutmapping'], function(ko, mapping) {
}

但是,映射未绑定到ko.mapping.任何指针/建议,将不胜感激.

However, mapping is not bound to ko.mapping. Any pointers/suggestions would be appreciated.

谢谢, 拉维

推荐答案

与AMD一起使用时,映射插件将其功能导出到单独的对象中.因此,该功能将附加到您的mapping变量,您可以从中调用方法(例如mapping.fromJS).

When used with AMD, the mapping plugin exports its functionality into a separate object. So, the functionality will be attached to your mapping variable and you would call methods off of it (like mapping.fromJS).

如果您具有无法更改的依赖于ko.mapping的代码,则可以选择在代码中将ko.mapping设置为等于mapping.

You could choose to set ko.mapping equal to mapping in your code, if you have code that relies on ko.mapping that you are unable to change.

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

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