3

meteor のautoform パッケージを使用していますが、コレクション内のドキュメントを更新しようとする_idと、レコードの更新を取得できないようです。

type=method-updateサーバー側で検証できるように、オートフォームを使用しています。_id以下のコードを試してみると、未定義のため失敗します。

テンプレート:

{{#autoForm collection="Lessons" doc=lesson id="updateLessonForm"  type="method-update" meteormethod="updateLesson"}}
        <fieldset>
            {{> afFieldInput name="categoryId" firstOption="(Select a Category)" options=categoryOptions}}
            {{> afQuickField name='title'}}
            {{> afQuickField name='summary' rows=2}}
            {{> afQuickField name='detail' rows=1}}
            {{> afQuickField name='extras' rows=1}}
            {{> afQuickField name='active'}}
        </fieldset>
        <button type="submit" class="btn btn-primary btn-block">Update Lesson</button>
    {{/autoForm}}

サーバー側の方法:

updateLesson: function (doc) {
    check(doc, Lessons.simpleSchema());
    Lessons.update({_id: this._id}, doc);
}

アップデート:

doc._id returns undefined

doc returns:
I20150409-23:15:22.671(-5)? { '$set': 
I20150409-23:15:22.672(-5)?    { categoryId: 1,
I20150409-23:15:22.672(-5)?      title: 'Lesson 1 update',
I20150409-23:15:22.672(-5)?      summary: 'Summary for lesson 2',
I20150409-23:15:22.672(-5)?      detail: '<p>dsffdsfd</p>',
I20150409-23:15:22.672(-5)?      extras: '<p>fdsf</p>',
I20150409-23:15:22.672(-5)?      active: false } }
4

1 に答える 1

2

if you print doc, you should get the document, so this._id should be changed to doc._id.

NOTE: try using console.log to see the values you are getting,before do the update.

console.log(this._id)//should return undefined.
console.log(doc._id)//should return the id
console.log(doc)//should return the doc.

Update

In order to get the _id, you should call a second parameter.

updateLesson: function (doc,doc_id) {
    check(doc, Lessons.simpleSchema());
    Lessons.update({_id: this._id}, doc);
}
于 2015-04-10T03:26:15.307 に答える