I have a simple dropdown list defined like this:
<div id="ActionMenu">
<input id="ddlActionList"
data-role="dropdownlist"
data-text-field="text"
data-value-field="value"
data-value-primitive="true"
data-bind="value: selectedAction, source: actionList"/>
</div>
And in another div I have a simple pop up window:
<div id="window"
data-role="window"
data-title="Message panel"
data-actions="['close']"
data-bind="visible: isVisible, enabled: isEnabled">
<p>Action selected: <span data-bind="text: getSelectedAction()"></span></p>
</div>
and it's all wrapped under an ActionMenu div.
this.ActionMenu = kendo.observable({
actionList: [{ text: 'Option A', value : 0 },
{ text: 'Option B', value : 1 },
{ text: 'Option C', value : 2 },
{ text: 'Option D', value : 3 }],
selectedAction: 0,
selectedActionText: function() {
// return what ?
}
}
});
My problem is that I have no way of grabbing the selected text from the Window view model:
this.MessageWindow = kendo.observable({
actions: ["Close"],
getSelectedAction: function (e) { return that.ActionMenu.get("selectedActionText"); }
});
If I do something like this:
var ddlActionList = that.kWidgetHelper.getWidgetInstance("ddlActionList");
ddlActionList.text();
That always returns the first text "Option A", not the selected one.
It would appear like an easy thing to do , but so far it's impossible for me to grab the selected text.
I also tried:
this.actionList[this.get("selectedAction")].text which produces an error.
I also tried:
selectedActionText: function(event) {
return event.sender.text();
}
Which doesn't work.
Also
selectedActionText: function() {
return that.ActionMenu.actionList[that.ActionMenu.selectedAction].text;
},
Always returns the first Option.
I believe my problem is that I am trying to get the current value of one viewmodel from another viewmodel.
Any ideas how to do that?
The text() method of the DDL should do the work if the DDL selection has changed, it should show the corresponding text.
The result should also be the same if you use the dataItem() method and then get the text property out of it.