hi,

you can use custom filter:

src/view/lib/filter_modules/<app_name>_custom_filters.erl

to_json(Record) when is_tuple(Record) ->
    Type = element(1, Record),
    boss_json:encode(Record:attributes(), [Type]);
to_json(Proplists) ->
    boss_json:encode(Proplists, []).


in your controller:

action('GET', []) ->
Condition = [],
Record = boss_db:find_first(my_model_name, Conditions),
{ok, [{record, Record}]).




in your template:
<script>

{% autoescape off %}
var data1 ={{ Record | to_json }};

var data2 ={{ Record.attributes | to_json }};
{% endautoescape %}

</script>


should work , you can easily modify it to your need.
Chan




2014-08-14 16:24 GMT+08:00 Caiyun Deng <[email protected]>:

> Hi!
> In the controller, "TestInfos = [[{name, "test1"}], [{name, "test2"}]],
> {ok, [{test_infos, TestInfos}]"
>
> In the javacript, the value is not json array.
> $(document).ready(function(){
>     console.log("*******", {{ test_infos }});
> It will  "Uncaught SyntaxError: Unexpected token , " --> 
> console.log("*******",
> {name,"test1"}{name,"test2"});
>
> I know i can return {json, [{test_infos, TestInfos]} to achieve this.
> But i want to return by {ok, [{test_infos, TestInfos}]} and the client get
> {{ test_info }} is a json array, so i can use javascript to handle it in
> some particular situations, not to request the server one more time to get
> the value.
>
> --
> You received this message because you are subscribed to the Google Groups
> "ChicagoBoss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at http://groups.google.com/group/chicagoboss.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chicagoboss/178cb911-a409-4dee-a7e0-e3ecf0ee8acf%40googlegroups.com
> <https://groups.google.com/d/msgid/chicagoboss/178cb911-a409-4dee-a7e0-e3ecf0ee8acf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/CAB-OfhkLb%2BzJynKV07ewq8rxdLqAOz-nyaaWTRkyzB3ZwNGsvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to