在我的应用程序中,每个视图都有自己的JS,用户可以点击“上传”按钮,文件上传模式显示>然后他从列表中选择图片>然后点击“保存”按钮:
fileUpload.js:
viewModel.prototype.save = function () {
cms.closeDialog(this, this.selectedObject());
};当用户点击“保存”按钮>图像的缩略图将显示在Products.html:中的专用div中。
<div data-bind="visible: thumbnailVisible">
<img data-bind="attr: { src: computedThumbnailUrl }, css: { 'cms-fileupload-thumbnail': isExternal }" alt="Image preview"/>
</div>Products.js:
fileUpload.prototype.fileUploaded = function (fileSize, fileName, extension) {
this.resetThumbnail();
this.value().fileName = fileName;
this.updateFileSize(fileSize);
if (this.uploadCallback) {
this.uploadCallback.call(this.context || this, fileName, extension);
}
};在fileUpload.js中的保存事件中,我试图调用存在于Products.js中的fileUploaded函数。
我怎样才能做到这一点?
发布于 2016-12-29 16:46:44
您的Product.js文件可能有如下内容:
var ProductModel = {
//code on this model
fileUpload.prototype.fileUploaded = function (fileSize, fileName, extension) {
this.resetThumbnail();
this.value().fileName = fileName;
this.updateFileSize(fileSize);
if (this.uploadCallback) {
this.uploadCallback.call(this.context || this, fileName, extension);
}
};
//code on this model
}正因为如此,当你试图从外部达到这个功能时,它不在当前的范围内。您可能需要使用在Products.js上设置模型的变量来调用您的函数。
https://stackoverflow.com/questions/41376911
复制相似问题