My api调用返回html,但如果该html为空,例如我得到一个控制台html响应“”,我想用knockout显示默认消息。所以我猜测它需要认识到“”是空的,然后显示我的备用内容。
视图模型 -如果HTML响应为空,则显示备用内容
var MyText = ko.observable();
var company = shell.authenticatedCompany();
hazibo.helpTextGet(company.name, company.userName, company.password).then(function (data) {
MyText(data);
});
return {
MyText: MyText
};
视图 -
<section class="help-text">
<div class="flex-container">
<div class="flex-item" data-bind="html: MyText">This is my alternate message if the html response is ""</div>
</div>
</section>