Knockout.js Magento2 knockoutjs,如何从自定义模块每秒更新标题中的客户名称?
我试图在m2中复制这个,但它不起作用。我从console.log(self.customer().fullname)获得的数据运行良好。但标题中的客户名称仍然没有更改 如果我喜欢这个:Knockout.js Magento2 knockoutjs,如何从自定义模块每秒更新标题中的客户名称?,knockout.js,magento2,Knockout.js,Magento2,我试图在m2中复制这个,但它不起作用。我从console.log(self.customer().fullname)获得的数据运行良好。但标题中的客户名称仍然没有更改 如果我喜欢这个: define(['uiComponent', 'ko', 'Magento_Customer/js/customer-data'], function (Component, ko, customerData) { "use strict"; return Component.extend({
define(['uiComponent', 'ko', 'Magento_Customer/js/customer-data'], function (Component, ko, customerData) {
"use strict";
return Component.extend({
initialize: function () {
var self = this;
this._super();
self.customer = customerData.get('customer');
self.customer().fullname = ko.observable(self.customer().fullname);
window.setInterval(function () {
var selectFruit = ["Apple", "Orange", "Banana", "Cherry"];
self.customer().fullname = selectFruit[Math.floor(Math.random() * 4)];
console.log(self.customer().fullname);
}, 500);
}
});
});
- 它工作得很好。但我想每秒钟改变一次这个值
你介意吗 我这样解决了这个问题:
self.customer().fullname = ko.observable('random text');
我不知道,但它是有效的。也许对某些人会有用 我这样解决了这个问题:
self.customer().fullname = ko.observable('random text');
我不知道,但它是有效的。也许对某些人会有用