简体   繁体   English

如何从Kendo MVVM数据绑定函数调用中获取实际的html元素

[英]How to get actual html element from Kendo MVVM data-bind function call

In my html template i used : 在我的html模板中,我使用了:

<div class="h-line" data-bind="style:{width:getWidth(this)}"> <hr /> </div>

In my viewModel i tried to get this element like this way : 在我的viewModel中,我试图以这种方式获取此元素:

getWidth: function (element) {
    console.log("Element", element);
    return ($("#preview-app").width()) + "px";
}

But i can't get the caller element in my console.log("Element", element) . 但是我无法在console.log("Element", element)获得caller元素。 Is there any way to get caller element using this model function ? 有什么方法可以使用此模型函数获取调用方元素吗?

Try this way > 尝试这种方式>

JS : JS:

getWidth: function () {
    return ($(".h-line").[0].offsetWidth) + "px";
}

HTML : HTML:

<div class="h-line" data-bind="style:{width:getWidth}"> <hr /> </div>

Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM