admin管理员组文章数量:1323729
I successfully filled my bobox. But now I'm trying to set default value for bobox. For example let's say third value from source. This is my input and datasource:
<script>
viewModel.dataSourceType = new kendo.data.DataSource({
transport: {
read: {
url: "/api/Type/Get",
dataType: "json"
}
},
schema: {
id: "Id",
data: "Data",
model: {
id: "Id",
fields: {}
}
}
});
<input id="type"
data-role="bobox"
data-value-primitive="true"
data-auto-bind="true"
data-text-field="Name"
data-value-field="Id"
data-bind="value: model.Id, source: dataSourceType">
It's probably really easy but I'm strugling with that. Thank you.
I successfully filled my bobox. But now I'm trying to set default value for bobox. For example let's say third value from source. This is my input and datasource:
<script>
viewModel.dataSourceType = new kendo.data.DataSource({
transport: {
read: {
url: "/api/Type/Get",
dataType: "json"
}
},
schema: {
id: "Id",
data: "Data",
model: {
id: "Id",
fields: {}
}
}
});
<input id="type"
data-role="bobox"
data-value-primitive="true"
data-auto-bind="true"
data-text-field="Name"
data-value-field="Id"
data-bind="value: model.Id, source: dataSourceType">
It's probably really easy but I'm strugling with that. Thank you.
Share Improve this question edited Dec 23, 2014 at 10:09 ManirajSS 2,3755 gold badges29 silver badges51 bronze badges asked Dec 10, 2014 at 14:18 user3573096user3573096 311 gold badge1 silver badge6 bronze badges3 Answers
Reset to default 4I assume you look for the index configuration option.
Likely the problem is in your model
definition, i.e. what you are binding to the bobox.
According with your definition your JavaScript should be something like:
var dataSource = new kendo.data.DataSource({
type: "odata",
transport: {
...
}
});
var model = new kendo.observable({
dataSourceType: dataSource,
model : { Id: 2 }
});
kendo.bind($("#type"), model);
Where 2
is the value that you want as default (initial) value.
Realize that I have had to declare an extra model
for Id
since you say in your data-bind
definition that value
is model.Id
.
Maybe you wanted to say:
var model = new kendo.observable({
dataSourceType: dataSource,
Id: 2
});
kendo.bind($("#type"), model);
And then you should define the HTML as:
<input id="type"
data-role="bobox"
data-value-primitive="true"
data-auto-bind="true"
data-text-field="Name"
data-value-field="Id"
data-bind="value: Id, source: dataSourceType">
$(document).ready(function() {
var dataSource = new kendo.data.DataSource({
type: "odata",
serverFiltering: true,
transport: {
read: {
url: "http://demos.telerik./kendo-ui/service/Northwind.svc/Products",
}
}
});
var model = new kendo.observable({
dataSourceType: dataSource,
Id: 2
});
kendo.bind($("#cbox"), model);
});
<link rel="stylesheet" href="http://cdn.kendostatic./2014.3.1119/styles/kendo.mon.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic./2014.3.1119/styles/kendo.default.min.css" />
<script src="http://cdn.kendostatic./2014.3.1119/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic./2014.3.1119/js/kendo.all.min.js"></script>
<input id="cbox"
data-role="bobox"
data-value-primitive="true"
data-auto-bind="true"
data-text-field="ProductName"
data-value-field="ProductID"
data-bind="value: Id, source: dataSourceType">
You can achieve like this.
var bobox = $("#kendoitems").data("kendoComboBox");
bobox.select(1);
you need to pass the index value to select(index).
Refer this http://jsfiddle/NdPze/63/
本文标签: javascriptKendo Ui comboboxset default valueStack Overflow
版权声明:本文标题:javascript - Kendo Ui combobox - set default value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742122006a2421755.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论