如何使用填充程序在requirejs中加载knockout.observableDictionary插件?

时间:2016-03-08 12:13:41

标签: javascript knockout.js requirejs

这是插件 https://github.com/jamesfoster/knockout.observableDictionary

这是一个小提示,显示我遇到的问题:

https://jsfiddle.net/L4d84nqc/1/

代码:

requirejs.config({
    paths: {
    'ko': 'https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min',
    'ko.observableDictionary' : 'https://rawgithub.com/jamesfoster/knockout.observableDictionary/master/ko.observableDictionary'
  },
  shim: {
    'ko.observableDictionary' : {
        deps: ['ko']
    }
  }
});


require(['ko', 'ko.observableDictionary'], function(ko) {
    console.log(ko);
});

1 个答案:

答案 0 :(得分:2)

我不认为有办法通过require注册添加属性(可能是错的?)。我只是将.js文件添加到包或页面中,并像这样修改库js ...

require(["ko"], function(ko){    
    (function (ko) {
        function DictionaryItem(key, value, dictionary) {
        .............. all that yummy code
        }
    })(ko)    
});