2
我想与搜索到的数据来更新我的数据绑定UL-李列表中的内容。我使用下面的视图模型ko.applyBinding使用Knockout刷新搜索结果?
function PatientsModel(data)
{
var self = this;
self.Patients = ko.observableArray([]);
self.Patients(data.Patients);
self.addPatient = function (model, event)
{
alert("Patients to Add: " + model.LastName + ',' + model.FirstName);
//Replace with AJAX Calls : self.people.push({ name: "New at " + new Date() });
};
self.removePatient = function (model, event)
{
alert("Patients to Delete:" + model.LastName + ',' + model.FirstName);
//Replace with AJAX calls : self.people.remove(this);
}
self.RefreshData = function (data)
{
self.Patients = ko.observableArray([]);
self.Patients(data.Patients);
}
}
刷新我已经创建RefreshData内容,方法是将更新患者这是数据绑定“的foreach:患者”符合UL
我做以下绑定:
AllPatientList.PatientsModel = null;
AllPatientList.PatientsModel = new PatientsModel(data);
ko.applyBindings(AllPatientList.PatientsModel, $('#AllPatientDiv>div>ul')[0]);
,并按照与更新视图模型的内容:
if (AllPatientList.PatientsModel != null && AllPatientList.PatientsModel != undefined)
{
AllPatientList.PatientsModel.RefreshData(data);
}
else
{
AllPatientList.PatientsModel = new PatientsModel(data);
ko.applyBindings(AllPatientList.PatientsModel, $('#AllPatientDiv>div>ul')[0]);
}
但它不起作用,UL的内容是不变。
而且我尝试做以下:
ko.cleanNode($('#AllPatientDiv>div>ul')[0]);
AllPatientList.PatientsModel = new PatientsModel(data);
ko.applyBindings(AllPatientList.PatientsModel, $('#AllPatientDiv>div>ul')[0]);
它是生产与重复/重复dataEntries名单。它显示9个列表项目而不是3个(每个重复3次)。
我无法弄清楚什么是错了,我在这里做。 ko.cleanNode()也不会从列表中删除内容。请帮助,我如何使用更新的内容重新绑定UL-LI列表。
#2抱着我选择答案:) – Sumeet
我不认为这句话有道理... – Tyrsius
这是怎么回事,因为你的回应工作马上,我试图选择它作为答案。但是,在提交问题之后有一个特定的时间段,只有在我可以选择一个响应作为ANswer之后。谢谢Tyrsius – Sumeet