Sitecore 8 SPEAK: получение ошибки при вызове метода в файле JS
Когда я вызываю метод в файле JS из приложения Sitecore SPEAK после нажатия кнопки, я получаю следующее сообщение об ошибке:
Ошибка типа: this.product не является функцией this.product()
this.product()
это имя функции:
define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
initialize: function (options) {
this._super();
},
products: function () {
var input = this.get("input");
$.ajax({
url: "/api/sitecore/Product/Find",
type: "POST",
data: { input: input },
context: this,
success: function (data) {
this.set("output", data);
}
});
},
product: function () {
var input2 = this.get("input2");
$.ajax({
url: "/api/sitecore/Product/FindSingle",
type: "POST",
data: { input2: input2 },
context: this,
success: function (data) {
this.set("output2", data);
this.set("output3", data.TitleS);
}
});
return null;
},
});
var view = Sitecore.Definitions.Views.ControlView.extend({
initialize: function (options) {
this._super();
},
product: function () {
this.product();
}
});
Sitecore.Factories.createComponent("ProductSearch", model, view, ".sc-ProductSearch");
});
Вызов вышеуказанного метода из события SPEAK Button.Click как:javascript: app.product ();
Что мы можем сделать, чтобы избежать такого случая?
3 ответа
Если это ваш PageCode для приложения SPEAK, можете ли вы обновить JavaScript, чтобы расширить Sitecore.Definitions.App, а не Sitecore.Definitions.Models.ControlModel.extend?
Например. определите приложение SPEAK следующим образом.
define(["sitecore", "jquery", "underscore"], function (Sitecore, $, _) {
var SpeakExample = Sitecore.Definitions.App.extend({initialize: function (options) {
},
products: function () {
var input = this.get("input");
$.ajax({
url: "/api/sitecore/Product/Find",
type: "POST",
data: { input: input },
context: this,
success: function (data) {
this.set("output", data);
}
});
},
product: function () {
var input2 = this.get("input2");
$.ajax({
url: "/api/sitecore/Product/FindSingle",
type: "POST",
data: { input2: input2 },
context: this,
success: function (data) {
this.set("output2", data);
this.set("output3", data.TitleS);
}
});
return null;
},return SpeakExample;});
Попробуй это,
define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
initialize: function (options) {
this._super();
app = this;
},
products: function () {}
});
}
И в кнопке нажмите тип: javascript:app.ProductSearch.product()
Попробуй позвонить this.model.product()
вместо this.product()
в методе продукта внутри определения вашего представления.