Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url Emberjs,瞄准一个模型而不离开'/型号';网址_Url_Ember.js_Model_Action_Edit - Fatal编程技术网

Url Emberjs,瞄准一个模型而不离开'/型号';网址

Url Emberjs,瞄准一个模型而不离开'/型号';网址,url,ember.js,model,action,edit,Url,Ember.js,Model,Action,Edit,我有一个模型表,我希望能够在其中一个模型中单击我的{{action'edit'},ember将知道{{action'edit'}}在哪个模型中 现在我收到了这个错误:“GET-localhost:3000/category/undefined 404(未找到)” 这是我在“/categories”路径中的代码 <tbody> {{#each}} <tr class="people-list"> <td>

我有一个模型表,我希望能够在其中一个模型中单击我的
{{action'edit'}
,ember将知道
{{action'edit'}}
在哪个模型中

现在我收到了这个错误:“GET-localhost:3000/category/undefined 404(未找到)”

这是我在“/categories”路径中的代码

<tbody>
    {{#each}}
      <tr class="people-list">
        <td>
            <input type="checkbox" class="toggle">
            {{#if isEdit}}
            {{view Ember.TextField valueBinding="Name" name="Name"}}
            {{else}}
            <label class="category-text">{{#linkTo 'category' this}}{{Name}}{{/linkTo}}</label>
            {{/if}}
            <img class="table-img" src="images/x.png">
            <img class="table-img" {{action 'edit'}} src="images/pencil-grey.png">
            </td>
        </tr>
    {{/each}}
</tbody>
404在我单击时发生

<img class="table-img" {{action 'edit'}} src="images/pencil-grey.png">
和router.js

  this.resource('categories', { path: '/categories' });
  this.resource('category', { path: '/category/:category_id' },function() { 
    this.route('edit');
  });

我不确定是否应该在路由器中添加任何关于“编辑”的内容,因为我不希望程序必须更改URL才能关注特定的模型。

有一个非常简单的解决方案,只需将模型发送到操作中即可

<img class="table-img" {{action 'edit' this}} src="images/pencil-grey.png">

actions: {
  edit: function(model){
    model.set('isEdit', true);
  }
}

有两个补充内容会很有帮助:1。您的应用程序映射(404和url中的“未定义”表示这是一个路由问题),2。模型结构的示例,以及3。您单击/执行的操作会产生此错误。您需要在每个操作中使用itemcontroller。你能创建一个JSFIDLE来说明这个问题吗?我已经更新了这个问题。我无法为此类问题设置JSFIDLE。不应包括this.route('edit')。您将“编辑”作为操作处理,而不是路由。尝试删除该行。一旦删除了“未定义”错误,我看到程序完全忽略了{{action'edit'this}}和{{action'edit}}。没有任何错误。现在,如果我使用了另一个操作,如“save”,我将收到错误“uncaughttypeerror:Object[Object Object]没有方法“save”’您有一个编辑操作,如果您添加了console.log,它是否命中了它?是console.log(“测试控制台”);在控制台中生成“测试控制台”。
  this.resource('categories', { path: '/categories' });
  this.resource('category', { path: '/category/:category_id' },function() { 
    this.route('edit');
  });
<img class="table-img" {{action 'edit' this}} src="images/pencil-grey.png">

actions: {
  edit: function(model){
    model.set('isEdit', true);
  }
}
App.CategoryRoute = Em.Route.extend({
  serialize: function(model){
    return {category_id: model.get('id')};
  }
});