我的问题有点类似于以下未回答的问题。(但不确定) Sitecore 8 SPEAK: Getting an Error When calling a Method in JS File
我正在使用Sitecore8
在我的页面上有一个按钮,在它的单击事件上,我想调用定制数据源组件的add()。
布局:

JS网页代码:
define(["sitecore"], function (Sitecore) {
var JsonListPage = Sitecore.Definitions.App.extend({
initialized: function () {
alert('Inside Json PageList Init');
},
loadData: function () {
alert('Button clicked');
app.add();
}
});
return JsonListPage;
});用于自定义数据源组件的JS代码:
define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
initialize: function (options) {
this._super();
this.set("json", null);
alert('Inside Jsondatasource Init');
},
add: function (data) {
var json = this.get("json");
if (json === null)
json = new Array();
// this is done because array.push changes the array to an object which then do no work on the SPEAK listcontrol.
var newArray = new Array(json.length + 1);
for (var i = json.length - 1; i >= 0; i--)
newArray[i + 1] = json[i];
newArray[0] = data;
this.set("json", newArray);
}
});
var view = Sitecore.Definitions.Views.ControlView.extend({
initialize: function (options) {
this._super();
this.model.set("json", null);
}
});
Sitecore.Factories.createComponent("JsonDatasource", model, view, ".x-sitecore-jsondatasource");
});用于自定义组件的.cshtml:
@using Sitecore.Mvc
@using Sitecore.Mvc.Presentation
@using Sitecore.Web.UI.Controls.Common.UserControls
@model RenderingModel
@{
var userControl = Html.Sitecore().Controls().GetUserControl(Model.Rendering);
userControl.Requires.Script("client", "JsonDatasource.js");
userControl.Class = "x-sitecore-jsondatasource";
userControl.Attributes["type"] = "text/x-sitecore-jsondatasource";
userControl.DataBind = "Json: json";
var htmlAttributes = userControl.HtmlAttributes;
}
<div @htmlAttributes>
am here again
</div>当页面加载时:
有一点我错过了。任何帮助都将不胜感激..。如果你还需要更多的投入,请告诉我。
提前感谢!
发布于 2015-10-09 12:52:44
app只有在调试模式下才可用,所以我避免使用它,而是使用"this“。
从您的代码示例中可以看出,您正在调用app.Add(),在您的pageCode上没有添加函数,这就是您的代码所要做的。相反,您需要访问组件的Add方法。
相反,要访问组件中的事件,需要调用如下函数:
this.ComponentID.Add();
我在这里有一个自定义语音组件的示例,您可以参考如何创建该组件。https://github.com/sobek1985/MikeRobbinsSPEAKRichTextEditor
从代码看来,您似乎创建了一个JSON数据源,Anders这里有一个示例http://laubplusco.net/creating-simple-sitecore-speak-json-datasource/
https://stackoverflow.com/questions/33037422
复制相似问题