我有一个用于添加多个地址的 html 表单:
http://i48.tinypic.com/jg2ruo.png
这样,如果我更改地址类型选择,整个表单必须绑定到正确的 json 地址对象:
var jsonAddresses = { Addresses:
[
{ AddressType: 1, Address1: "", Address2: "",Province:"",City:"",State:"",PostalCode:"",Municipal:"" },
{ AddressType: 2, Address1: "", Address2: "",Province:"",City:"",State:"",PostalCode:"",Municipal:"" },
{ AddressType: 3, Address1: "", Address2: "",Province:"",City:"",State:"",PostalCode:"",Municipal:"" },
{ AddressType: 4, Address1: "", Address2: "",Province:"",City:"",State:"",PostalCode:"",Municipal:"" }
]
};
实际上,我已经使用 Jquery 完成了很多代码,但我想知道如何使用 Knockout 来做到这一点。这个想法不是拥有一个具有 4 种地址类型的固定 json 对象,我只想拥有 1 个 json 对象,如果我选择不在数组中的地址类型,则添加并绑定对象,如果地址类型已经存在于数组中然后绑定它。然后我可以有一个“删除”链接,单击该链接时,选定的地址类型对象将从数组中删除。
提前致谢。