Home > Backend Development > PHP Tutorial > javascript - Backbone开发中遇到set的一个问题?

javascript - Backbone开发中遇到set的一个问题?

WBOY
Release: 2016-06-06 20:20:35
Original
1159 people have browsed it

先上json的数据格式,底部有完整的php

<code>{    
  "id":0,
  "success": true,
 
  "user":{
    "ready":"0",
    "name":"",       //这里声明了name,没有声明tel
    "sex":"",
    "addr":[{"prov":"1省","city":["a","b","c"]},
            {"prov":"2省","city":["aa","bb","cc"]},
            {"prov":"3省","city":["aaa","bbb","ccc"]}],
    "birth":"1992-06-15",
    "wx":""
  }
}
</code>
Copy after login
Copy after login

问用set方法创建tel的值?

<code>user=this.model.get('user');
user.tel=123;
this.model.set('user',user)
</code>
Copy after login
Copy after login

上面这个方法在实际用法无效 tel的值没有加进来

javascript - Backbone开发中遇到set的一个问题?

这里却又值

javascript - Backbone开发中遇到set的一个问题?

如果文件中存在一个属性,他是可以传值的;

<code>user=this.model.get('user');
user.name=123;//tel换成name
this.model.set('user',user)

</code>
Copy after login
Copy after login

javascript - Backbone开发中遇到set的一个问题?

javascript - Backbone开发中遇到set的一个问题?

访问的数据文件如下:

<code><?php if($_SERVER['REQUEST_METHOD']=="PUT"){
    //echo json_encode(array("status"=>true));
    
    parse_str(file_get_contents('php://input'),$put_vars);
    
    $put_vars=json_encode($put_vars);
    die($put_vars);
    die;
    }

else{
echo '{
  "id":0,
  "success": true,
 
  "user":{
    "ready":"0",
    "name":"",
    "sex":"",
    "addr":[{"prov":"1省","city":["a","b","c"]},
            {"prov":"2省","city":["aa","bb","cc"]},
            {"prov":"3省","city":["aaa","bbb","ccc"]}],
    "birth":"1992-06-15",
    "wx":""
  }
}';
}</code>
Copy after login
Copy after login

回复内容:

先上json的数据格式,底部有完整的php

<code>{    
  "id":0,
  "success": true,
 
  "user":{
    "ready":"0",
    "name":"",       //这里声明了name,没有声明tel
    "sex":"",
    "addr":[{"prov":"1省","city":["a","b","c"]},
            {"prov":"2省","city":["aa","bb","cc"]},
            {"prov":"3省","city":["aaa","bbb","ccc"]}],
    "birth":"1992-06-15",
    "wx":""
  }
}
</code>
Copy after login
Copy after login

问用set方法创建tel的值?

<code>user=this.model.get('user');
user.tel=123;
this.model.set('user',user)
</code>
Copy after login
Copy after login

上面这个方法在实际用法无效 tel的值没有加进来

javascript - Backbone开发中遇到set的一个问题?

这里却又值

javascript - Backbone开发中遇到set的一个问题?

如果文件中存在一个属性,他是可以传值的;

<code>user=this.model.get('user');
user.name=123;//tel换成name
this.model.set('user',user)

</code>
Copy after login
Copy after login

javascript - Backbone开发中遇到set的一个问题?

javascript - Backbone开发中遇到set的一个问题?

访问的数据文件如下:

<code><?php if($_SERVER['REQUEST_METHOD']=="PUT"){
    //echo json_encode(array("status"=>true));
    
    parse_str(file_get_contents('php://input'),$put_vars);
    
    $put_vars=json_encode($put_vars);
    die($put_vars);
    die;
    }

else{
echo '{
  "id":0,
  "success": true,
 
  "user":{
    "ready":"0",
    "name":"",
    "sex":"",
    "addr":[{"prov":"1省","city":["a","b","c"]},
            {"prov":"2省","city":["aa","bb","cc"]},
            {"prov":"3省","city":["aaa","bbb","ccc"]}],
    "birth":"1992-06-15",
    "wx":""
  }
}';
}</code>
Copy after login
Copy after login

主要是由于model模型中不存在tel的值;所以无法被保存;所以要在模型的默认属性中先添加tel(空值也好,反正要声明)

你倒底想问什么??先把错别字改掉,把话讲通顺了。


你前端是修改了值然后传到后台吗?把前端的相关代码贴出来吧

既然POST到php的数据是有tel的,说么Model的数据已经修改了,去检查你php的代码,这和Backbone无关

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template