jamiemthomas / jquery-datalink

A data linking plugin for jQuery.
http://jamiemthomas.github.com/jquery-datalink
5 stars 2 forks source link

Possible to turn null into an empty string? #1

Closed DrZim closed 14 years ago

DrZim commented 14 years ago

We started using your fork in our solution. It really works well. One issue is that a link when null actually says "null" when rendered. In the parent, it turns null values to empty strings.

A plus seems to be your solution doesn't fail like the parent. If we rendered 100 products in the parent, it would get a stack overflow. We successfully rendered 137 products without issues in yours. Our object is nested with eight levels.

jamiemthomas commented 14 years ago

@DrZim, would you please git the latest changes I checked in today, which currently includes a small jquery.datalink mod as well (to support named converters, not just named converter functions). I included in this checkin changes to how values are converted to string, and actually delayed the conversion process until after the main template rendering, thereby allowing me to call the optional converter specified with the link to handle the conversion process.

This means that all values rendered by the template actually will flow through your converters, if specified, before being inserted as an attribute or element value in the DOM, and will include both the source (your object) and the target (the DOM element) as parameters. For things like dates, this enables you to perform custom formating (see the updated contact demo). And in the case of the Age field in the contact demo, the converter is actually able to manipulate the size of the input control inside the converter as part of the initial template render. Also, I am not currently calling $.encode() on the value before inserting it (not sure if this is necessary/desirable yet, but this is what was occurring in the previous version based on the ${} implementation, which does return "null" for null. I testing putting a null value in the contact demo, and it now displays blank as you would expect.

I am glad to hear the fork is proving useful! I wish Boris and Dave would go ahead and release the version they are working on, but I know it will be functionally comparable, and I need to move forward with our efforts to migrate from the MSAJAX client templates. I appreciate your feedback!

DrZim commented 14 years ago

That worked like a charm. We loaded about 70k of JSON which had about 250 products, e.g., 250 templates with several nested arrays that had several nested arrays within them. It grabbed and rendered the entire thing in 3 seconds. Our older solution wouldn't get beyond 50 products, and the JQuery templates you forked from didn't do more than 100 products when we had half the html in the template. Your memory management, software, and talent is amazing.

Now if we could get MVC 2 Futures to bind the JSON correctly for doubles and DateTimes, we would be great (both are 0).

Thanks for the code. We will keep you posted on it's success.

jamiemthomas commented 14 years ago

Glad to hear it worked well. The delclarative linking defers insertion of your converted data into the DOM until after template rendering, so the template engine is only creating a string containing the HTML markup, without data. I imagine on a much larger dataset there would still be problems with the jquery templating implementation, but it is correctable through incremental rendering. I will post a note to that effect on your other issue.

I am closing this issue, but feel free to create others as you continue to encounter problems. I am working on test cases for creating and binding to every type of form element right now, and expect to find a few bugs/gotchas myself.