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>