将 jQuery 模板与复杂对象结合使用并从子集合中获取值
在我的 jQuery 模板中,我需要获取数据结构子集合中包含的项目的值。
假设我有一个如下所示的数据结构:
<Quote>
<AgentName></AgentName>
<AgentId></AgentId>
<QuoteId></QuoteId>
<ProductId></ProductId>
<ProductName></ProductName>
<Benefits>
<Benefit>
<Name>Benefit One</Name>
<Description>This is benefit One</Description>
<Value>5000000</Value>
<ValueComment></ValueComment>
<Excess>200</Excess>
<ExcessComment></ExcessComment>
</Benefit>
<Benefit>
<Name>Benefit Two</Name>
<Description>This is benefit Two</Description>
<Value>1000</Value>
<ValueComment></ValueComment>
<Excess>100</Excess>
<ExcessComment></ExcessComment>
</Benefit>
</Benefits>
<Price>10.99</Price>
</Quote>
然后我可以将其转换为如下所示的 JSON 字符串:
[{"AgentName":null,"AgentId":null,"QuoteId":null,"ProductId":"abc","ProductName":"Standard","Benefits":[{"Name":"Benefit One","Description":"\n This is benefit One \n ","Value":5000000,"ValueComment":null,"Excess":200,"ExcessComment":null},{"Name":"Benefit Two","Description":"\n This is benefit Two\n ","Value":1000,"ValueComment":null,"Excess":100,"ExcessComment":null}],"Price":10.99}
在我的 jQuery 模板中,我想创建一个表来显示产品 ID、产品名称、价格以及仅显示的值好处一:
<script id="QuoteTemplate" type="text/x-jQuery-tmpl">
<tr>
<td valign="middle" style="width: 120px; text-align: left; font-weight:bold" class="quote-row"> ${ProductId} </td>
<td valign="middle" style="width: 140px; text-align: center; font-weight:bold" class="quote-row"> ${ProductName} </td>
// Somehow need to query the benefits collection to get only the value of Benefit One
<td valign="middle" style="width: 140px; text-align: center; font-weight:bold" class="quote-row"> ${ ***ONLY BENEFIT ONE*** .value } </td>
<td valign="middle" style="width: 140px; text-align: center; font-weight:bold" class="quote-row"> ${Price} </td>
</tr>
</script>
感谢您的帮助。
In my jQuery template I need to get the value of an item that is contained within a subcollection of my data structure.
Say I have a data structure that looks like this:
<Quote>
<AgentName></AgentName>
<AgentId></AgentId>
<QuoteId></QuoteId>
<ProductId></ProductId>
<ProductName></ProductName>
<Benefits>
<Benefit>
<Name>Benefit One</Name>
<Description>This is benefit One</Description>
<Value>5000000</Value>
<ValueComment></ValueComment>
<Excess>200</Excess>
<ExcessComment></ExcessComment>
</Benefit>
<Benefit>
<Name>Benefit Two</Name>
<Description>This is benefit Two</Description>
<Value>1000</Value>
<ValueComment></ValueComment>
<Excess>100</Excess>
<ExcessComment></ExcessComment>
</Benefit>
</Benefits>
<Price>10.99</Price>
</Quote>
I can then convert this into a JSON string that looks like this:
[{"AgentName":null,"AgentId":null,"QuoteId":null,"ProductId":"abc","ProductName":"Standard","Benefits":[{"Name":"Benefit One","Description":"\n This is benefit One \n ","Value":5000000,"ValueComment":null,"Excess":200,"ExcessComment":null},{"Name":"Benefit Two","Description":"\n This is benefit Two\n ","Value":1000,"ValueComment":null,"Excess":100,"ExcessComment":null}],"Price":10.99}
In my jQuery Template I want to create a table that shows the Product ID, Product Name, Price and ONLY the value of Benefit One:
<script id="QuoteTemplate" type="text/x-jQuery-tmpl">
<tr>
<td valign="middle" style="width: 120px; text-align: left; font-weight:bold" class="quote-row"> ${ProductId} </td>
<td valign="middle" style="width: 140px; text-align: center; font-weight:bold" class="quote-row"> ${ProductName} </td>
// Somehow need to query the benefits collection to get only the value of Benefit One
<td valign="middle" style="width: 140px; text-align: center; font-weight:bold" class="quote-row"> ${ ***ONLY BENEFIT ONE*** .value } </td>
<td valign="middle" style="width: 140px; text-align: center; font-weight:bold" class="quote-row"> ${Price} </td>
</tr>
</script>
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,以下对我有用: {{= Benefits[0].Value}}
基本上,Benefits 是一个数组,因此我们采用该数组的第一个值,即 Benefits 并显示 Value 实体
Hello the following has worked for me: {{= Benefits[0].Value}}
Basically, Benefits is an array so we take the first value of that array which is benefits one and show Value entity