Vincent Pérès
unread,May 12, 2009, 10:46:49 AM5/12/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to chainjs
Hello,
I'm parsing and displaying results from JSON datas thanks to Chain.
But it appears an error when an element is missing ("field" is not
defined, error from Chain).
Example (missing description field in the second element) :
<docs>
<doc>
<field name="title">blabla</field>
<field name="description">blabla</field>
</doc>
<doc>
<field name="title">blabla</field>
</doc>
<doc>
<field name="title">blabla</field>
<field name="description">blabla</field>
</doc>
</docs>
Now I have two different needs :
1. builder[".description"] = "description"
I solved it by building a custom builder :
builder['.description'] = function(data, el) {
if (data['description'] != '' && data[value['field']] !=
undefined) {
return data['description'];
} else {
return '';
}
};
2. builder[".description"] = "<img src='link' alt='{description}' />"
It's working, but I case where the field is missing, I don't have an
alternative (like I wrote above).
Do you have any idea which could help me to build a custom builder and
parse a string inside, or anything else?
Thank you very much.
Vincent