簡體   English   中英

bone.js沒有保存具有更新屬性的模型

[英]backbone.js is not saving model with updated attributes

usersCollection.fetch({
    success: function () {
        var getModel = usersCollection.where(checkIDJSON);
        //update that partcular attribute
        getModel.set('interest', 'rolling stones');
        console.log("Users:" + usersCollection.toJSON());

    },
    error: function () {
        // something is wrong..
    }

});

運行代碼后,在嘗試保存到模型時,它抱怨該函數未定義。 知道為什么嗎? 謝謝

我在Titanium Mobile中使用ribs.js

精美的手冊中

where collection.where(attributes)

返回集合中與傳遞的屬性匹配的所有模型的數組。

所以當你這樣說:

var getModel = usersCollection.where(checkIDJSON);

您最終在getModel得到了一系列模型。 如果您確定只有一種模型可以匹配,請使用findWhere

findWhere collection.findWhere(attributes)

就像where一樣,但是只直接返回集合中與傳遞的屬性匹配的第一個模型。

像這樣:

var getModel = usersCollection.findWhere(checkIDJSON);

如果可能有多個匹配項,那么大概您想在每個匹配項上調用set

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM