在从函数返回值之前保存空变量

时间:2016-10-13 10:11:14

标签: javascript jquery sharepoint

我正在尝试使用以下查询保存数据

Server Error in '/WebLITE' Application.

Type 'ASP.index_aspx' does not inherit from `System.Web.UI.UserControl`.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Type 'ASP.index_aspx' does not inherit from 'System.Web.UI.UserControl'.

Source Error: 

framejson的代码在

之下
var content = framejson($(e.target));
        //alert(wpId);
        var dfd = $.Deferred();
        setTimeout(function(){
        saveWebPartProperties(wpId, { Description: content }).done(function () {
                dfd.resolve();
                $(e.target).closest("table").find(".successmessage").show();
            }).fail(self.error);
        },500);

现在在我尝试保存json内容的代码中,当我删除警报或删除function framejson(elem){ var listname={}; listname["Name"] = $(elem).closest("table").find(".Name").val(); listname["Length"] = $(elem).closest("table").find(".Length").val(); return JSON.stringify(listname); };

时,会保存空值

只有我有警报或setTimeout或我通过控制台调试

时才能正常工作

我还尝试使用setTimeoutdeferred,但它没有用。只有setTimeout使它工作,我试图理解为什么

when

造成这个问题的错误是什么?

2 个答案:

答案 0 :(得分:1)

正如您在此代码段中看到的,这很好用。 所以我想你的问题不在于这个显示的代码。

$(".test").on('click', function(e){
  var content = framejson(e.target);
  console.log(content)
});

function framejson(elem){
   var listname={};
   listname["Name"] = $(elem).closest("table").find(".Name").val();
   listname["Length"] = $(elem).closest("table").find(".Length").val();
   return JSON.stringify(listname);
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td><input class="Name" value="bla" /></td>
    <td><input class="Length" value="ert" /></td>
    <td><button class="test">test</button></td>
   </tr>
 </table>

答案 1 :(得分:0)

以下代码有效,

DB::select(DB::raw("exec dbo.sp_getDepends :Action, :DependencyID"),
[':Action' => $Action, ':DependencyID' => $DependencyID]);

我认为原因是,在从framejson函数返回内容之前,保存部分被调用

我使用create or replace function get_gewicht_product(p_dieet_id number) return number is cursor c_Rids is select recept_id from relation_6 where dieet_id = p_dieet_id; type type_coll_med is table of relation_5%rowtype index by pls_integer; t_med type_coll_med; product_id number; gewicht_id number; restvoorraad_id number; result number; begin for r_med in c_Rids loop select * bulk collect into t_med from relation_5 where recept_recept_id = r_med.recept_id; for i in 1 .. t_med.count loop select restvoorraad into restvoorraad_id from voorraad where product_product_id=t_med(i).product_product_id; dbms_output.put_line(t_med(i).gewicht); dbms_output.put_line(restvoorraad_id); gewicht_id := t_med(i).gewicht; result := restvoorraad_id-gewicht_id; dbms_output.put_line(result); update voorraad set restvoorraad = result where product_id = t_med(i).product_product_id; end loop; end loop; return 1; end get_gewicht_product; var wpId=$(e.target).parents().closest(".ms-rtestate-field").parent().attr("webpartid"); var content = $.Deferred(); content.resolve(framejson($(e.target))); $.when(content).done(function(value){ var dfd = $.Deferred(); saveWebPartProperties(wpId, { Description: value }).done(function () { dfd.resolve(); $(e.target).closest("table").find(".successmessage").show(); }).fail(self.error); }); 来解决此问题。一旦内容从函数返回值,其余代码就会被调用以保存它