jQuery를 사용하여 드롭 다운 목록에서 특정 항목을 제거 할 필요가 없습니다.
Kendo DataSource 개체와 해당 MVVM 패턴을 사용하여 원하는 것을 얻을 수 있습니다.
는 다음과 같이 HTML은 다음과 같습니다
<input id='dropdownlist' data-role="dropdownlist"
data-text-field="ProductName"
data-value-field="ProductID"
data-bind="value: selectedProduct,
source: products" />
<button id="button" type="button">Remove current item</button>
<br />
<input class='k-textbox' id='specificItem' />
<button id="removeSpecificButton" type="button">Remove specific item</button>
를 그리고 자바 스크립트가 될 것입니다 :
http://dojo.telerik.com/@BenSmith/aCEXI/11
:
// Use a viewModel, so that any changes to the model are instantly applied to the view.
// In this case the view is the dropdownlist.
var viewModel = kendo.observable({
selectedProduct: null,
products: new kendo.data.DataSource({
transport: {
read: {
url: "//demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
}
}
})
});
kendo.bind($("#dropdownlist"), viewModel);
$("#removeSpecificButton").kendoButton({
click: function(e) {
// Find the item specified in the text box
viewModel.products.filter({
field: "ProductName",
operator: "eq",
value: $('#specificItem').val() });
// Apply the view to find it
var view = viewModel.products.view();
//remove the item from the datasource
viewModel.products.remove(view[0]);
// disable the filter
viewModel.products.filter({});
}
});
// Set-up the button so that when it is clicked
// it determines what the currently selected dropdown item is
// and then deletes it.
$("#button").kendoButton({
click: function(e) {
// Determine which item was clicked
var dropdownlist = $("#dropdownlist").data("kendoDropDownList");
var dataItem = dropdownlist.dataItem();
// Remove that item from the datasource
viewModel.products.remove(dataItem);
}
});
내가 여기서 일이의 예를 작성했습니다 exac를 지정하기 위해 DataSource의 "필터"메소드가 사용 된 방법에 주목하십시오. (이 경우 ProductName)을 제거해야합니다. 항목을 제거한 후에는 더 이상 필요없는 항목없이 필터를 제거하여 데이터를 표시 할 수 있습니다.
또한 현재 선택한 항목을 완전하게 제거 할 수있는 기능이 포함되어 있습니다.
내 대답이 도움이 되었습니까? –