Combobox 转向数据[i]['Value']; } } 返回null; } 这无疑是一个非常愚蠢的问题,但在Razor语法中,这与OP的代码有何相似之处?当我转换它时,它从不调用函数。这对于不匹配的值没有改变的情况是没有用的。未触发任何更改事件。 @Html.Kend
转向数据[i]['Value']; } } 返回null; }Combobox 转向数据[i]['Value']; } } 返回null; } 这无疑是一个非常愚蠢的问题,但在Razor语法中,这与OP的代码有何相似之处?当我转换它时,它从不调用函数。这对于不匹配的值没有改变的情况是没有用的。未触发任何更改事件。 @Html.Kend,combobox,kendo-ui,Combobox,Kendo Ui,转向数据[i]['Value']; } } 返回null; } 这无疑是一个非常愚蠢的问题,但在Razor语法中,这与OP的代码有何相似之处?当我转换它时,它从不调用函数。这对于不匹配的值没有改变的情况是没有用的。未触发任何更改事件。 @Html.Kendo() .ComboBoxFor(model => model.CountryCode) .BindTo(ViewBag.Countries as IEnumerable<SelectListItem>)
这无疑是一个非常愚蠢的问题,但在Razor语法中,这与OP的代码有何相似之处?当我转换它时,它从不调用函数。这对于不匹配的值没有改变的情况是没有用的。未触发任何更改事件。
@Html.Kendo()
.ComboBoxFor(model => model.CountryCode)
.BindTo(ViewBag.Countries as IEnumerable<SelectListItem>)
.Filter(FilterType.StartsWith)
.Placeholder("Country")
.HtmlAttributes(new { @class = "span9" })
var comboId = '#movies';
alert(GetComboBoxValue(comboId));
function GetComboBoxValue(comboId){
var comboValue = -1;
$(comboId).data('kendoComboBox').select(function (dataItem) {
// Note: you have to perhaps change the property - text as per the value
// this is for the example provided in the link only
if (dataItem.text == $(comboId').data('kendoComboBox').text()){
comboValue = dataItem.value;
break;
}
});
//will return -1, if data is not found from the list
return comboValue;
}
change : function (e) {
if (this.value() && this.selectedIndex == -1) { //or use this.dataItem to see if it has an object
alert('Invalid Entry!');
cb.select(1);
}
}
@(Html.Kendo().ComboBox()
.Name("cb")
.Events(it => it.Change("cbIsChanged"))
...
)
<script>
cbIsChanged = function (e) {
...
}
</script>
$(document).ready(function() {
var items = [
{value : '1',
desc : 'fred'},
{value : '2',
desc : 'wilma'},
{value : '3',
desc : 'pebbles'},
{value : '4',
desc : 'dino'}
];
var cb = $('#comboBox').kendoComboBox({
dataSource : items,
dataTextField : 'desc',
dataValueField : 'value',
filter : 'contains',
change : function (e) {
if (this.value() && this.selectedIndex == -1) {
this._filterSource({
value: this.value(),
field: this.options.dataTextField,
operator: "contains"
});
this.select(0);
if ( this.selectedIndex == -1 ) {
this.text("");
}
}
}
}).data('kendoComboBox');
});
<div class="form-group">
@Html.LabelFor(model => model.GlAccount, new { @class = "control-label col-md-4" })
<div class="col-md-6">
@(Html.Kendo<OrderRequest>().ComboBoxFor(m => m.GlAccount).DataValueField("Number").DataTextField("Description").Filter(FilterType.Contains).HighlightFirst(true)
.DataSource(src => src.Read(read => read.Action("GetGlAccounts", "Lookup", new { area = "" }))).Events(events => events.Change("app.common.onChangeRestrictValues")))
@Html.ValidationMessageFor(model => model.GlAccount)
</div>
<script>
function onChangeRestrictValues(e) {
if (this.value() && this.selectedIndex == -1) {
var dt = this.dataSource._data[0];
this.text(dt[this.options.dataTextField]);
this.select();
}
}
</script>
$(document).ready(function() {
var items = [
{value : '1',
desc : 'fred'},
{value : '2',
desc : 'wilma'},
{value : '3',
desc : 'pebbles'},
{value : '4',
desc : 'dino'}
];
var cb = $('#comboBox').kendoComboBox({
dataSource : items,
dataTextField : 'desc',
dataValueField : 'value',
filter : 'contains',
change : function (e) {
if (this.value() && this.selectedIndex == -1) {
this._filterSource({
value: "",
field: this.options.dataTextField,
operator: "contains"
});
this.select(1);
}
}
}).data('kendoComboBox');
$('#showValue').click(function () {
alert(cb.value());
});
<div id="main_pane_add_truck" data-role="view" data-model="APP.models.main_pane_add_truck">
<input id="main_pane_add_truck_customer_id" data-role="combobox" data-placeholder="Type a Customer" data-value-primitive="true" data-text-field="Name" data-value-field="CustomerID"
data-bind="value: customer_id, source: customer_id_ds, events: { change: customer_id_change }" />
</div>
window.APP = {
models: {
main_pane_add_truck: kendo.observable({
customer_id: null,
customer_id_ds: new kendo.data.DataSource({
type: "odata",
transport: {
read: ROOTURL + BODYURL + "MyCustomers"
},
schema: {
model: {
fields: {
CustomerID: { type: "number" },
Name: { type: "string" },
}
}
}
}),
customer_id_change: function customer_id_change(e) {
try {
var found = false;
var combobox = $("#main_pane_add_truck_customer_id").data("kendoComboBox");
var customer_id = e.data.customer_id;
var dataSource = this.get("customer_id_ds");
var data = dataSource.data();
var data_length = data.length;
if (data_length) {
for (var i = 0; i < data_length; i++) {
if (data[i].CustomerID === customer_id) {
found = true;
}
}
if (!found) {
this.set("customer_id", data[0].CustomerID);
combobox.select(0);
}
}
else {
this.set("customer_id", null);
}
}
catch (e) {
console.log(arguments.callee.name + " >> ERROR >> " + e.toString());
}
},
}),
}
};