当以下 foreach 被绑定时,我需要能够让视图将 html 从 $.get 或硬编码添加到“body”div。我需要“模型”成为那个 vm,但我不知道如何让 vm 将 html 添加到页面
<!--ko foreach:modules -->
<div class="module" data-bind="attr: {id:id}">
<div class="head" data-bind="text:title"></div>
<div class="body" data-bind=""></div>
</div>
<!-- /ko -->
my.Module = function (mod) {
var m = mod || { },
id = m.id || new Date().getTime(),
css = ko.observable(m.css || { }),
title = ko.observable(m.title || 'New Module'),
privy = ko.observable(),
model = ko.observable(new my.Models.DailyStatus());
return {
id: id,
css: css,
title: title,
privy: privy,
model: model
};
};
my.Models.DailyStatus = function () {
var venues = ko.observableArray(),
init = function () {
//Get HTML specific to my needs
//Add to desired area of page
//?????
// Get data to fill venues
update();
},
update = function () {
my.service.getNewVenues(function (c) {
venues(c.d.Payload);
});
};
init();
return {
init: init,
update: update,
venues: venues
};
};
有没有办法让我的模型知道他的宿主是什么元素?