在ViewModel中绑定了一个与另一个
我正在使用MVVM使用Kendo jQuery。
当另一个变量更改(“ optionID”)时,我想自动更改变量(“标签”)的值。
这是我的viemodel:
var vm = kendo.observable({
optionId: '',
label: ( this.optionId == 'Spaghetti' ? "Pasta selected" : "Animal selected" ),
setOption: function( event ) {
var value = event.currentTarget.value;
this.set("optionId", value );
//this.set("label", this.optionId == 'Spaghetti' ? "Pasta selected" : "Animal" );
}
});
如果我删除注释的行,则可以正常工作。但这不是我想要的,因为我必须在每种方法中添加该行。
我以为我可以写:
label: ( this.get("optionId") == etc... )
但是我不能。我相信这会起作用。
这是Kendo Dojo的示例。
https://dojo.telerik.com/agewiwak
非常感谢。
I'm using Kendo JQuery with MVVM.
I would like to automatically change the value of the a variable ("label") when another variable changes ("optionId").
This is my VieModel:
var vm = kendo.observable({
optionId: '',
label: ( this.optionId == 'Spaghetti' ? "Pasta selected" : "Animal selected" ),
setOption: function( event ) {
var value = event.currentTarget.value;
this.set("optionId", value );
//this.set("label", this.optionId == 'Spaghetti' ? "Pasta selected" : "Animal" );
}
});
If I remove the commented line, it works. But that's not what I want because I would have to add that line in every method.
I thought I could write:
label: ( this.get("optionId") == etc... )
but I can't. I believe this would work.
Here is an example on Kendo Dojo.
https://dojo.telerik.com/agewIWAk
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的解决方案,来自Telerik论坛:
https> https:// www。 telerik.com/forums/in-viewmodel-binds-value-with-anther
Here the solution, from Telerik forum:
https://www.telerik.com/forums/in-viewmodel-binds-value-with-another