Jquery Sitecore 8 SPEAK:在JS文件中调用方法时出错
单击按钮后,我从Sitecore SPEAK应用程序调用JS文件中的方法时,会收到以下错误消息: 类型错误:此.product不是函数 this.product()Jquery Sitecore 8 SPEAK:在JS文件中调用方法时出错,jquery,sitecore,Jquery,Sitecore,单击按钮后,我从Sitecore SPEAK应用程序调用JS文件中的方法时,会收到以下错误消息: 类型错误:此.product不是函数 this.product() this.product()是函数名: define(["sitecore"], function (Sitecore) { var model = Sitecore.Definitions.Models.ControlModel.extend({ initialize: function (options) {
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();
}
}))
}))
从SPEAK按钮调用上述方法。单击事件作为:
javascript:app.product()强>
我们可以做些什么来避免这种情况?尝试调用
this.model.product()
而不是this.product())
在视图定义内的product方法中。如果这是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;});
试试这个
定义([“sitecore”],函数(sitecore){
var模型=Sitecore.Definitions.Models.ControlModel.extend({
初始化:函数(选项){
这个;
app=这个;
},
产品:函数(){}
});
}
您是否已将PageCode组件添加到页面中?是的,PageCode已添加到布局的顶部。您可以发布整个js代码吗?如果扩展方法正在扩展,似乎一切都应该正常工作。您的代码是否放置在这样的扩展块中定义([“sitecore”],函数(sitecore){var app=Sitecore.Definitions.app.extend({?我这里有一个示例SPEAK PageCode。DeleteArticle和AddArticle连接到SPEAK按钮。你的PageCode与此不同吗?我已经用整个代码更新了js代码@sobek1985是的,它与我的不同,所以我会检查一下。你使用的是哪个版本的Sitecore?
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;});