我一直在使用以下代码将viewModels绑定到其他项目中,并且必须为magento 2稍微修改一下。也许我只是看了太长时间,但这是我的问题。< / p>
在以下代码段中,我收到错误无法设置属性&#39; categoryViewModel&#39;未定义虽然记录它似乎应该定义。那里有什么想法吗?
demoController.js
define('js/theme',[
'jquery',
'knockout',
'category',
'product',
'domReady!'
], function ($, ko, categoryView, productView) {
'use strict';
var demoController = {
init: function(){
var self = this;
var shouter = new ko.subscribable();
categoryView.categoryViewController(shouter);
productView.productViewController(shouter);
self.masterVM = (function(){
this.categoryViewModel = new categoryView.categoryViewModel();
this.productViewModel = new productView.productViewModel();
})();
ko.applyBindings(self.masterVM);
}
};
demoController.init();
});
categoryView.js
define([
'jquery',
'knockout'
], function($, ko) {
var categoryView = {
categoryViewController: function(shouter){
//var self = this;
this.categoryViewModel = function(){
this.foo = ko.observable('category!');
console.log('category view', this.foo() );
};
}
};
return categoryView;
});