简体   繁体   English

将HTML属性绑定到XML数据源

[英]Bind HTML Attribute to XML Data Source

I am not that familiar with the whole SGML family... I need to develop a small website which is part of an installation process of an application. 我对整个SGML系列不是很熟悉...我需要开发一个小网站,这是应用程序安装过程的一部分。 The website shows permanently the features which were selected during the installation process. 该网站会永久显示在安装过程中选择的功能。 The website is fine - thanks to Bootstrap. 该网站很好-感谢Bootstrap。 But now I want to hide or show elements on this website according to the selection in the installation process. 但是现在我要根据安装过程中的选择隐藏或显示此网站上的元素。

During the installation I can modify an XML file. 在安装过程中,我可以修改XML文件。 My idea is to bind the HTML attributes to the XML data. 我的想法是将HTML属性绑定到XML数据。

Example XML I can modify during my installation process: 我可以在安装过程中修改的示例XML:

<features>
 <feature>
  <name>Feature 1</name>
  <visible>hidden</visible>
 <feature>  
<features>

HTML idea: HTML想法:

<div class="feature1" VISIBLE_VALUE_FROM_XML>
 <img src="./img/feature1"/>
</div>

Is it somehow possible to bind both? 是否可以将两者绑定? What are the relevant keywords here? 这里有哪些相关的关键字? What alternatives do I have? 我有什么选择? Do you have any good reading sources? 您有什么好的阅读资料吗?

Thanks! 谢谢!

[EDIT]: [编辑]:

Perhaps the question was too trivial for you. 也许这个问题对您来说太琐碎了。 I guess I was too limited in Data Binding thinking. 我想我在数据绑定思想方面太局限了。 So, the following steps do the trick: 因此,以下步骤可以解决问题:

  1. leave your desk 离开你的桌子
  2. grab a coffee 喝一杯咖啡
  3. smoke a cigarette, if you like 抽烟,如果你喜欢
  4. use JS and traverse the XML tree 使用JS并遍历XML树

Here You GO! 干得好!

With these steps you can do it. 通过这些步骤,您可以做到。

Step 1 : Convert your XML to JSON using any one of the libraries (like jquery XML2JSON) 第1步:使用任何一种库(例如jquery XML2JSON)将XML转换为JSON

Step 2 : Select your "DIV" with id with jquery($("#yourid")) and modify the visibility according to the value of the visibility property in your json 第2步:使用jquery($(“#yourid”))选择ID为ID的“ DIV”,并根据json中的visible属性的值修改可见性

(e.g)

if(json[feature].visibility=="hidden")
{
$("#yourid").hide();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 HTML 属性与 jQuery 进行数据绑定 - How to data-bind HTML attribute with jQuery 如何将服务器生成的html数据绑定到淘汰模型属性中? - How to bind server generated html data into knockout model attribute? html元素的“ dir”属性(rtl / ltr)的数据绑定 - data-bind for the “dir” attribute (rtl/ltr) of html element AngularJS:如何对HTML5数据属性使用ng-bind / ng-bind-template - AngularJS: How to use ng-bind/ng-bind-template for HTML5 Data attribute 如何在不使用html属性标记数据绑定值的情况下与Knockout绑定? - How can you bind with Knockout without using the html attribute tag data-bind value? jQuery将此绑定到数据属性 - JQuery bind this and data-attribute Javascript/HTML/Puppeteer - 如何访问属性数据绑定中的值(单击按钮)? - Javascript/HTML/Puppeteer - How to access the values from the attribute data-bind (to click a button)? 如何在Mvc助手中使用Knockout的数据绑定属性,如Html.EditorFor() - How to use Knockout's data-bind attribute in Mvc helpers like Html.EditorFor() 将kendo ui数据源绑定到规范化数据 - bind kendo ui data source to normalized data Angular JS-绑定自定义html属性 - Angular JS - bind a custom html attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM