나는 검도 UI가 중첩 뷰 모델 바인딩에 대한 좋은하지 않는 경향이 있기 때문에 당신이 내부 뷰 모델 접근 방식 문제로 실행할 수 있습니다 생각합니다. 내가 아는 한, 모든 검도 UI 위젯은 그 때문에 내부 위젯을 코드로 작성합니다.
사이드 노트 : 위젯에서 DOM 요소를 드롭 다운 요소로 사용했습니다. 동일한 페이지에 위젯을 여러 개 만들면 중복이 생성됩니다. 이 경우 클래스를 사용하는 것이 좋습니다.
getYear: function() {
return this._getWidget("year").value();
},
setYear: function (value) {
this._getWidget("year").value(value);
console.log(this._getWidget("year"));
}
전체 :
kendo.data.binders.widget.year = kendo.data.Binder.extend({
init: function (element, bindings, options) {
kendo.data.Binder.fn.init.call(this, element, bindings, options);
var that = this;
that.element.bind("change", function() {
that.change(); //call the change function
});
},
refresh: function() {
var that = this,
value = that.bindings.year.get();
this.element.setYear(value);
},
change: function() {
var value = this.element.getYear();
this.bindings.year.set(value);
}
});
이 이러한 접근을 제공하는 위젯 작동합니다 :
는 다음과 같이 보일 수있는하는
custom binder을해야하는
year
바인딩을 사용하려면 위젯 예제 (완전히 구현되지 않았 음을 유의하십시오 - 연도 바인딩과 기간 설정 만 고려함) :
(function ($) {
var kendo = window.kendo,
ui = kendo.ui,
Widget = ui.Widget,
periods = [
{ text: "PERIOD: YEAR", value: "YEAR" },
{ text: "PERIOD: QUARTER", value: "QUARTER" }
],
quarters = [
{ text: "1. Quarter", value: 1 },
{ text: "2. Quarter", value: 2 },
{ text: "3. Quarter", value: 3 },
{ text: "4. Quarter", value: 4 }
],
years = [2011, 2012, 2013, 2014];
var LinkedDropDowns = Widget.extend({
init: function (element, options) {
var that = this,
periodOption = $(element).data("period");
if (periodOption) {
this.options.period = periodOption;
}
Widget.fn.init.call(that, element, options);
that._create();
// make sure view state is correct depending on selected period
this._getWidget("period").trigger("change");
},
options: {
name: "LinkedDropDowns",
period: "YEAR",
periods: periods,
year: 2011,
years: years,
quarter: 1,
quarters: quarters,
selectedYear: 2011
},
onPeriodChange: function (e) {
switch (e.sender.value()) {
case "YEAR":
$(this._getWidget("year").wrapper).show();
$(this._getWidget("quarter").wrapper).hide();
break;
case "QUARTER":
$(this._getWidget("year").wrapper).show();
$(this._getWidget("quarter").wrapper).show();
break;
default:
break;
}
},
onChange: function() {
// trigger change so the binder knows about it
this.trigger("change", { sender: this });
},
_getWidget: function (name) {
var el = $(this.element).find("input." + name).first();
return el.data("kendoDropDownList");
},
_create: function() {
var that = this;
// create dropdowns from templates and append them to DOM
that.periodDropDown = $(that._templates.periodDropDown);
that.yearDropDown = $(that._templates.yearDropDown);
that.quarterDropDown = $(that._templates.quarterDropDown);
// append all elements to the DOM
that.element.append(that.periodDropDown)
.append(that.yearDropDown)
.append(that.quarterDropDown);
$(this.element).find(".period").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
value: this.options.period,
change: this.onPeriodChange.bind(that),
dataSource: this.options.periods
});
$(this.element).find(".year").kendoDropDownList({
dataSource: this.options.years,
change: this.onChange.bind(this)
});
$(this.element).find(".quarter").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: this.options.quarters
});
},
_templates: {
periodDropDown: "<input class='period' />",
yearDropDown: "<input class='year' style='width: 90px' />",
quarterDropDown: "<input class='quarter' style='width: 110px' />"
},
getYear: function() {
return this._getWidget("year").value();
},
setYear: function (value) {
this._getWidget("year").value(value);
console.log(this._getWidget("year"));
}
});
ui.plugin(LinkedDropDowns);
})(jQuery);
(demo)
위젯 생성을위한 kendo 튜토리얼을 참조하십시오 : -http : //blogs.telerik.com/kendoui/posts/12-04-03/creating_custom_kendo_ui_plugins –