Hello Jeremy,

That is very close to what I was thinking about, but probably your 
implementation is better.
What I was actually looking for is to clearNonStandardFields. From the code 
I understood that every field set as undefined will remain empty. From what 
you write I understand that every undefined field will be eliminated. What 
version is correct?

Why do you pass the wiki as parameter? this function will be inside the 
widget, so it should be able to access via this.wiki.

Thank you very much for your help!

El viernes, 4 de abril de 2014 16:09:23 UTC+2, Jeremy Ruston escribió:
>
> Hi Danielo
>
> My goal is to take a tiddler and clear all its fields except the standard 
>> ones. At a first instance my flow it was going to be like this:
>>
>>    1. Take the tiddler from the store. 
>>    2. Copy all its fields to a new temp object
>>    3. Create a new empty tiddler.
>>    4. I suppose the empty tiddler has just the standard fields. 
>>    5. Delete those fields from my temp object.
>>    6. Clear all the fields in the temp object.
>>    7. Create a new tiddler with this order wiki.addTiddler(new 
>>    $tw.Tiddler(oldTiddler,tempObject)) 
>>
>> I think what you need is something like this:
>
> function removeNonStandardFields(wiki,title) {
> var standardFieldNames = "title text tags modified modifier created 
> creator".split(" "),
>  tiddler = wiki.getTiddler(title);
> if(tiddler) {
> var clearFields = {};
>  for(var fieldName in tiddler.fields) {
> if(standardFieldNames.indexOf(fieldName) === -1) {
>  clearFields[fieldName] = undefined;
>  }
> }
> wiki.addTiddler(new $tw.Tiddler(tiddler,clearFields));
>  }
> }
>
> Basically, any field set to "undefined" at the end of the cascade in the 
> $tw.Tiddler constructor will ensure that that field is absent from the 
> resulting tiddler.
>
> Best wishes
>
> Jeremy
>
>
>  
>
>> But the problem is that the new tiddler has any field. 
>>
>> El jueves, 3 de abril de 2014 19:18:30 UTC+2, Jeremy Ruston escribió:
>>>
>>> Hi Danielo
>>>
>>> In TiddlyWiki, tiddler objects are immutable; once one has been created 
>>> the values of the fields cannot be changed. In 5.0.9, that restriction is 
>>> enforced, but at the moment there's nothing to stop erroneous code 
>>> modifying a tiddler object.
>>>
>>> To modify a tiddler, one instead overwrites the tiddler in the store 
>>> with a new tiddler with the same title. Here's the crucial line from the 
>>> function you quoted:
>>>
>>> self.wiki.addTiddler(new $tw.Tiddler(self.wiki.getCreat
>>> ionFields(),tiddler,updateFields,self.wiki.getModificationFields()));
>>>
>>> If we separate things out, you can see that the constructor for 
>>> $tw.Tiddler is being called with four parameters. Each one is a hashmap of 
>>> field values; they are merged left to right, so that the rightmost field 
>>> with the same name wins. The resulting tiddler is then passed to 
>>> addTiddler() to add it to the store.
>>>
>>> Best wishes
>>>
>>> Jeremy
>>>
>>>
>>>
>>> On Thu, Apr 3, 2014 at 12:53 PM, Danielo Rodríguez <[email protected]>wrote:
>>>
>>>> Thank you BJ,
>>>>
>>>> Then, what is the difference between using $tw.wiki.addTiddler(tiddler) 
>>>> and new $tw.Tiddler() ?
>>>> Could you explain me the syntax?
>>>>
>>>> El jueves, 3 de abril de 2014 10:15:14 UTC+2, BJ escribió:
>>>>
>>>>>
>>>>> HI Danielo,
>>>>> with the tw5 code, the Tiddler object  is like a house that the actual 
>>>>> 'tiddler' ocupies. the actual 'tiddler' is known by it name, stored in 
>>>>> title field. When the 'tiddler' changes in some way it need to change its 
>>>>> house. the call to  new $tw.Tiddler() get a new house for the tiddler. 
>>>>> The 
>>>>> actual 'tiddler' itself is the data inside the old Tiddler object that 
>>>>> must 
>>>>> be copied (and changed) and put in the new Tiddler object. Hope that 
>>>>> helps!
>>>>>
>>>>> cheer
>>>>>
>>>>> Jeff
>>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "TiddlyWikiDev" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>>
>>>> Visit this group at http://groups.google.com/group/tiddlywikidev.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Jeremy Ruston
>>> mailto:[email protected]
>>>  
>>
>
>
> -- 
> Jeremy Ruston
> mailto:[email protected] <javascript:>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.

Reply via email to