Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Aurelia-如何从jquery函数访问类属性?_Aurelia - Fatal编程技术网

Aurelia-如何从jquery函数访问类属性?

Aurelia-如何从jquery函数访问类属性?,aurelia,Aurelia,我和jquery一起处理Aurelia时遇到了一些问题 我试图从jCrop函数(这是一个jquery)访问类中的“model”,但得到的消息是“model未定义” ModalCrop.js export class ModalCrop{ @bindable({ defaultBindingMode: bindingMode.twoWay }) image = ''; model = { ImageURL: this.imageBase64, Positi

我和jquery一起处理Aurelia时遇到了一些问题

我试图从jCrop函数(这是一个jquery)访问类中的“model”,但得到的消息是“model未定义”

ModalCrop.js

export class ModalCrop{
  @bindable({ defaultBindingMode: bindingMode.twoWay }) image = '';

  model = {
        ImageURL: this.imageBase64,
        PositionX: 0,
        PositionY: 0,
        Width: 0,
        Height: 0
    };

  imageChanged(newValue, oldValue){
        var imageCrop = $(this.thepicture);
        imageCrop.jWindowCrop({
            targetWidth:500,
            targetHeight:500,
            onChange: function(result) {
                this.model.Width = result.cropW;
            }
        });
    }
}
HTML组件

<div class="modal-image-content">
     <img ref="thepicture" src="${image}">
</div>


有人能帮我吗?

问题是范围问题。要修复此问题,请将
onChange
函数调用更改为使用粗箭头函数,如下所示:

onChange: (result) => {
            this.model.Width = result.cropW;
        }

如果这不起作用,只需添加
var self=this
当您的
图像中的第一行更改了
函数,然后将
this.model.Width
更改为
self.model.Width

Felipe时,我注意到您问了几个问题(我回答了其中两个),但您没有接受任何问题的答案。当您收到满意的答案时,您应该单击您认为最有帮助的答案左侧的复选标记。这有助于StackOverflow.com正常工作。它还可以帮助个人用户获得成功答案的积分。非常感谢。