1

FW/1 は、完全な Web ページを返すことを重視しているようです。JSON データが必要な場合はどうなりますか? 典型的なレイアウトは次のようになります。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <title>User Manager</title>
   <link rel="stylesheet" type="text/css" href="assets/css/styles.css" />
</head>
<body>


<h1>User Manager</h1>

<ul class="nav horizontal clear">
<li><a href="index.cfm">Home</a></li>
<li><a href="index.cfm?action=user.list" title="View the list of users">Users</a></li>
<li><a href="index.cfm?action=user.form" title="Fill out form to add new user">Add User</a></li>
<li><a href="index.cfm?reload=true" title="Resets framework cache">Reload</a></li>
</ul>

<br />

<div id="primary">
    <cfoutput>#body#</cfoutput>
</div>

</div>

</body>
</html>
4

3 に答える 3

7

FW/1 2.2 では、以下を呼び出すことができます。

variables.fw.renderData( "json", result );

あなたのコントローラーで、それはあなたが望むことをします。

于 2013-12-11T06:04:46.623 に答える
3

onMissingView()Framework.cfcのメソッドをオーバーライドするコードを使用しました。

という名前の変数で応答をラップrc.jsonし、Application.cfc でこれと同様のコードを使用します。

function onMissingView( rc ){
    if( structKeyExists( rc, 'json' ){
        var response = getPageContext().getresponse()
        response.setContentType( 'application/json' );
        return serializeJSON( rc.json );
    }
    else{
        //we need this to fire off valid onMissignView error.
        raiseException( "FW1.viewNotFound", "Unable to find a view for '#request.action#' action.", " '#request.missingView#' does not exist.");
    }
}

リクエストが AJAX リクエストでない場合は、他のロジックを使用してcfdumpofを実行します。rc.jsonしかし、これは最小限に縮小されています。

于 2013-08-26T16:50:33.427 に答える
1

これでできます

 <!--- Load all variables into response rather than just rc --->
 <cfparam name="rc.response" default="#structNew()#">
 <cfparam name="rc.response.status" default="OK">

 <!--- Stop layouts from cascading --->
 <cfset request.layout = false>

 <cfsetting showDebugOutput="No">
 <cfheader name="Content-Type" value="application/json" />

  <cfoutput>#SerializeJSON(rc.response)#</cfoutput>
于 2013-08-26T16:33:29.453 に答える