Ajuda com KnockoutJS + RequireJS + Magento
Pessoal tudo bem?
Tenho um arquivo em knckoutJS do meu site em magento
define(
[
'jquery',
'ko',
'uiComponent',
'mage/url',
'mage/storage',
'Teste_AdvancedGrid/js/view/price',
'Magento_Customer/js/customer-data'
],
function ($, ko, component, urlBuilder, storage , priceRender, customerData) {
"use strict";
return component.extend({
// CLASS Product
Product : function(id, sku , name , urlThumb ) {
this.id = ko.observable(id);
this.sku = ko.observable(sku);
this.name = ko.observable(name);
this.urlThumb = ko.observable(urlThumb);
},
// CLASS CartItem
CartItem : function(product, quantity) {
var self = this; // Scope Trick
self.product = ko.observable(product);
self.quantity = ko.observable(quantity || 1);
self.cost = ko.computed(function(){
return self.product().price() * self.quantity();
});
self.increaseQuantity = function() {
self.quantity(self.quantity() + 1);
};
self.formatMoney = function() {
return "R$ " + self.cost().toFixed(2);
};
},
// CLASS ViewModel
ViewModel : function() {
/**
* Scope Trick
* @type {[type]}
*/
var self = this;
getModel: function(data, event) {
var brand = $("#marca").val();
var self = this;
var serviceUrl = urlBuilder.build('/grid/index/product?type=model&brand='+brand);
return storage.get(serviceUrl,'').done(
function (response) {
var dados = JSON.parse(response);
self.model(dados);
}
).fail(
function (response) {
console.log(response);
}
);
},
initialize: function () {
this._super();
},
_render:function(){
},
defaults: {
template: 'Teste_AdvancedGrid/grid',
},
});
}
);
E tenho um JS que é invocado na mesma pagina com RequireJS
requirejs(['algoliaBundle', 'knockout'], function(algoliaBundle , ko) {
algoliaBundle.$(function ($ ,ko ) {
if (!this.ko) {
this.ko = ko;
};
//AQUI QUE QUERO INVOCAR A FUNÇÂO DO KNOCKOUT
this.getModel(parametro);
});
});
Eu gostaria de chamar a função do Knockout "getModel" no arquivo acima passando um parametro como this.getModel(parametro) , mas não sei como invocar a view model no arquivo acima, alguem pode me ajudar ? Não sei como instaciar a View Model do magento no requireJSDiscussão (0)
Carregando comentários...