0
public class model
{
public int modelid { get; set; }
public string name { get; set; }
public List<childModel> childModel{ get; set; }
}
public class childModel
{
public int childModelid { get; set; }
public string childname { get; set; }
}
Java腳本
@{
var datam = new JavaScriptSerializer().Serialize(Model);
}
var helloWorldModel = {
model: ko.mapping.fromJS(@Html.Raw(datam)),
dele: function (models) {
helloWorldModel.model.remove(models);
}
}
ko.applyBindings(helloWorldModel);
HTML
<span data-bind="foreach:model">
<span data-bind="text : name"></span>
<span data-bind="foreach:childmodel">
<input type="text" data-bind="value:childname" />
</span>
<input type="button" data-bind="click:$parent.dele" value="delete parent" />
</span>
這樣我就可以刪除的模式,但有什麼辦法可以去除childmodel蒙山此結構體? 是這樣的:
deleChildModel: function (Childmodels) {
helloWorldModel.model.childModel.remove(Childmodels);
}
我可以新增modelid到ChildModel然後用
deleChildModel: function (Childmodels) {
helloWorldModel.model()[Childmodels.modelid].childModel.remove(Childmodels);
}
,但我要找的東西簡單
感謝,它的工作原理 –
@PooriyaArazesh請註明的答案,當你得到一個機會接受。 –