It has a method calld .value() - that didn't work, dataItem.value did not work either.
Finaaly out of desperation, I realized that I had the data item, and thought, perhaps it contains the field names, just like the json delivered to it. The solution was simply to specify dataItem.xxx where xxx is the name of the field I wanted to the value from. Here's the code example:
@(Html.Kendo().DropDownListFor(model => model)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetTableList", "Lists");
});
})
.DataTextField("DisplayName")
.DataValueField("id")
//.DataValueField("ANAPatternDesc")
//.SelectedIndex(0)
.Name("dlTableNames")
.OptionLabel("- Please select -")
.Events(e => e.Select("TableSelected"))
.ValuePrimitive(true)
.HtmlAttributes(new { style="width:400px" })
)
JavaScript to get the value:
function TableSelected(e) {
var item = e.item;
var text = item.text();
var dl = $("#dlTableNames").data("kendoDropDownList").dataSource;
var dataItem = this.dataItem(e.item);
//alert($("#dlTableNames").getKendoDropDownList().dataSource.data().length);
alert(dataItem.id);
Note the commented line, this feature is cool, if the drop downlist is not data bound it will return an empty array, otherwise it will return an array of itesm
very great
ReplyDeleteit's helpful to me.