Please tell me what's wrong with this script

6 views
Skip to first unread message

Dave Parker

unread,
Nov 22, 2009, 12:39:35 PM11/22/09
to TiddlyWiki
Hi, I have this script that I stole from one of Eric's answers to
someone and tried to modify it like this:


<script>
var out=[]; var fmt='| %0|%1|';
var tids=store.getTaggedTiddlers('qwerty');
for (var i=0; i<tids.length; i++)
{
out.push(tids[i].title);
for (var f in tids[i].fields)
if (tids[i].fields[f]=true)
{
out.push(fmt.format([f,tids[i].fields[f]]));
}
}
return out.join('\n');
</script>

It used to just make a table that lists the fields of a tiddler and
the fields' contents. What I want it to do is just list the fields
and contents that are "true" (as defined by checkboxes attached to the
tiddlers fields). Instead, what this script does is cause all fields
to be true, even the "changecount" field that's supposed to be a
number.

I'm obviously slow when it comes to scripting, but a little help would
be greatly appreciated.

Oh, here's the original script and context with the checkboxes:
----
checkboxes that toggle fields:

[_(Left@)] Left ... [_(Right@)] Right ... [_(bilateral@)] bilateral

<script>
var out=[]; var fmt='| %0|%1|';
var tids=store.getTaggedTiddlers('qwerty');
for (var i=0; i<tids.length; i++)
{
out.push(tids[i].title);
for (var f in tids[i].fields) out.push(fmt.format
([f,tids[i].fields[f]]));
}
return out.join('\n');
</script>
----
Thanks,
Dave Parker

Eric Shulman

unread,
Nov 22, 2009, 12:58:00 PM11/22/09
to TiddlyWiki
> if (tids[i].fields[f]=true)

a single "=" is an *assignment* operator, so that
tids[i].fields[f]=true
sets the value of the indicated field to TRUE

a double "==" is a *comparison* operator, so that
tids[i].fields[f]==true
results in a TRUE or FALSE expression based on the current field value

-e

Dave Parker

unread,
Nov 22, 2009, 1:37:49 PM11/22/09
to TiddlyWiki
Thanks Eric,

Nice to see that you're back. :-)


At first I was going to ask another question, but tried the if
statement with "true" in quotes instead of no quotes, and that fixed
it.
Thanks very much for both this and your patience (with slow learners
like me) and dedication.

-Dave
Reply all
Reply to author
Forward
0 new messages