remove([set of values])
优质
小牛编辑
122浏览
2023-12-01
描述 (Description)
KnockoutJS Observable remove([set of values])方法删除与给定值集匹配的项。
语法 (Syntax)
arrayName.remove([set of values])
参数 (Parameters)
此方法以值集的形式接受参数。
例子 (Example)
<!DOCTYPE html>
<head>
<title>KnockoutJS ObservableArray remove multiple method</title>
<script src = "https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js"
type = "text/javascript"></script>
</head>
<body>
<p>Example to demonstrate remove([set of values]) method.</p>
<button data-bind = "click: removemultiEmp">Remove multiple Emps</button>
<p>Array of employees: <span data-bind = "text: empArray()" ></span></p>
<script>
function EmployeeModel() {
this.empName = ko.observable("");
this.chosenItem = ko.observableArray("");
this.empArray = ko.observableArray(['Scott','James','Jordan','Lee',
'RoseMary','Kathie']);
this.removemultiEmp = function() {
alert("This function is removing multiple matching items e.g.['RoseMary','Lee'].");
this.empArray.removeAll(['RoseMary','Lee']);
}
}
var em = new EmployeeModel();
ko.applyBindings(em);
</script>
</body>
</html>
输出 (Output)
让我们执行以下步骤来查看上述代码的工作原理 -
将以上代码保存在array-remove-set.htm文件中。
在浏览器中打开此HTML文件。
单击“删除多个Emps”按钮。