开发者

Accessing: name="recipe[''name'] inJavascriptMVC

开发者 https://www.devze.com 2023-03-07 03:35 出处:网络
I run through this Making a Cookbook tutorial (http://javascriptmvc.com/docs.html#&who=getstarted)

I run through this Making a Cookbook tutorial (http://javascriptmvc.com/docs.html#&who=getstarted)

Since I work with rails i changed the input names from name and description to recipe['name'] and recipe['description']

Saving the record via rails work fine, but as soon as JMVC updates the vie开发者_运维问答w it renders [object Object] instead of the title/description

Controller:

'form submit': function( el, ev ){
    ev.preventDefault();
    new Cookbook.Models.Recipe(el.formParams()).save();
},
'recipe.created subscribe': function( called, recipe ){
    $("#recipe tbody").append( this.view("list", {recipes:[recipe]}) );
    $("#recipe form input[type!=submit]").val(""); //clear old vals
},

Form:

<form>
        <div class="field">
        <label for="recipe_name">Name</label><br>
        <input type="text" size="30" name="recipe[name]" id="recipe_name">
      </div>

        <div class="field">
            <label for="recipe_description">Description</label><br>
            <input type="text" size="30" name="recipe[description]" id="recipe_description">
          </div>
    <input type='submit' value='Create'/>
</form>


Ask questions on JavaScriptMVC's forum. I don't check Stackoverflow that often.

The problem is you should be passing to Recipe(el.formParams().recipe). Model expects attributes.

0

精彩评论

暂无评论...
验证码 换一张
取 消