Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Is is possible to combine an XML based ItemTemplate with some template elements defined in code?

$
0
0

Hi all,

I'm trying to work with a dynamic ListViewItem that can potentially have several input fields, depending on the number of attributes.

I understand in order to accomplish this, I have to create the template with the required number of child templates at runtime in the template dictionary, but my ItemTemplate is very complex due to the needed styling, so I've defined it in XML / TSS.

What I'm wondering is if it's possible to combine this XML based ItemTemplate with the dynamic properties dictionary defined when you append items to the list section.

Here's a small contrived example to illustrate what I'm thinking:

item_template.xml:

<ItemTemplate name="cartItem">
   <Label id="itemTitle" bindId="itemTitle" />
   <View id="containerView" bindId="containerView">
   </View>
</ItemTemplate>
shopping_cart.js:
function generateCartItems() {
   var itemTemplate = {
      title: { text: "My Item" },
      containerView: {
         visible: true,
         childTemplates: [
            {
               type: 'Ti.UI.TextField',
               bindId: 'testyTest',
               properties: {
                  font: { fontSize: '14dp' },
                  width: "200px",
                  height: "50px"
               },
               value: "This field should be added to the containerView"
            }
         ]
      },
      template: "cartItem",
      properties: {
      }
   };
 
   return [itemTemplate, itemTemplate];
}
 
var cartDataItems = generateCartItems();
$.itemListSection.appendItems(cartDataItems);
Assuming I have a list section defined with the id 'itemListSection', I would imagine the above would create two list view items that have a dynamically created textfield, contained in the 'containerView' view from the XML file. However, this isn't the case.

Does anybody know how to accomplish this hybrid template definition style? Or am I stuck with attempting to get it all done via the dictionary method with childTemplates?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>